我使用以下 SQL 来获取内容的位置。
$leftBlock ='l';
$rightBlock ='r';
$topBlock = 'c';
$bottomBlock = 'd';
$blockposition = array();
$result2 = $db->sql_query("SELECT bposition FROM {$prefix}_blocks_manager WHERE module_title ='$name'");
while($row2 = $db->sql_fetchrow($result2)) {
$blockposition[] = $row2['bposition'];
}
$blockposition2 = array_unique($blockposition);//remove duplicates becouse db output can be like:lllrrrd
if (in_array($leftBlock, $blockposition2) AND in_array($rightBlock, $blockposition2)) {
$mytestresult = "We go use a template with left and right blocks";
}
if (in_array($leftBlock, $blockposition2) AND !in_array($rightBlock, $blockposition2)) {
$mytestresult = "We go use a template with just left blocks";
}
if (!in_array($leftBlock, $blockposition2) AND in_array($rightBlock, $blockposition2)) {
$mytestresult = "We go use a template with just right blocks";
}
if (!in_array($leftBlock, $blockposition2) AND !in_array($rightBlock, $blockposition2)) {
$mytestresult = "We go use a template with just content";
}
$name
代表我正在查看的页面。
$mytestresult
将告诉 Twig 加载特定的模板:
$template = $twig->loadTemplate('mytestresult_file.phtml');
但是对于上面的每个模板,我可以创建在现有内容之上或之下添加新内容的内容。
$topBlock
和$bottomBlock
在我的脚本中,我将所有左/右/上/下块加载到一个函数中blocks($side) { .....
blocks('l') blocks('r') blocks('c') blocks('d')
$topBlocks
如果上面的 4 个模板之一还包含和/或$bottomBlock
s 内容,我需要一种方法来告诉 TWIG 如何渲染。
默认情况下,不加载上面的 4 个模板中的任何一个,我渲染如下:
// render template
echo $template->render(array (
'title' => $title1,
'metaDesc' => $metaDesc,
'metaKeywords' => $metaKeywords,
'navContent' => $navContent,
'leftContent' => $leftContent,
'defaultContent' => $module_content,
'rightContent' => $rightContent,
'footerContent' => $copyright
));
但在这种情况下,即使没有任何内容,twig 也会渲染 rightContent 的 html。