Доброго времени суток! Не могу решить вопрос -
В главный шаблон нужно вывести блоки страницы
БАЗА
site_pagesid | parent | ...
1 | page |
site_pages_blocks
id | page_id | module_id | module_name | action | pos | property1 | roperty2
1 | 1 | 1 | articles | showarticles | 1 | 1 | null
Мой код
function get_block($id){GLOBAL $db;
$arr=array();
$result=$db->sql_query("select * from `site_pages_blocks` where `page_id`='".$id."' order by `pos`");
while ($res=$db->sql_fetchrow($result)){$arr[]=$res;}
return $arr;
}
$arr_block = array();
$arr_block = get_block($PAGE['id']);
foreach($arr_block as $arr){
switch ($arr[module_id]) {
case '1':
if($arr[action]=='showpublic'){
$articles=$db->sql_fetchrow($db->sql_query("select * from `site_articles` where `id`='".$arr['property1']."'"));
$smarty->assign('articles',$articles);
}
break;
case '2':
if($arr[action]=='shownews'){
$result=$db->sql_query("select * from `site_news` where `parent`='".$arr['property1']."'");
while ($res=$db->sql_fetchrow($result))$arr_news[]=$res;
$smarty->assign('news',$arr_news);
}
break;
}}
$smarty->assign('block',$arr_block);
$smarty->assign('tpl_name', 'block');
block.tpl
{if is_array($block)}
{foreach from=$block item=bx }
{if $bx.module_id=='1'}{include file="articles.tpl"}
{elseif $bx.module_id=='2'}{include file="news.tpl"}
{/if}
{/foreach}
{/if}
index.tpl
<html>
<head>
<title>{$SITETITLE}</title>
<meta name="keywords" content="">
<meta name="description" content="" />
<meta http-equiv="content-language" content="ru">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
</head>
<body style="margin:0px; padding:0px;">
{$PAGENAME}
{include file="$tpl_name.tpl"}
</body>
</html>
И он естественно работает не корректно. ПОМОГИТЕ ПЛИЗ!