次の 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 もレンダリングします。