我使用以下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
會去告訴嫩枝加載特定的模板:
$template = $twig->loadTemplate('mytestresult_file.phtml');
但對於每個模板上面,我可以創造內容,增加了現有內容的上方或下方的新內容。
$topBlock
和$bottomBlock
裏面我的劇本我加載所有的左/右/上/下塊的功能blocks($side) { .....
blocks('l') blocks('r') blocks('c') blocks('d')
我需要一種方法來告訴TWIG如何渲染,如果上述4個模板中的一個還包含$topBlocks
和/或$bottomBlock
的內容。
// render template
echo $template->render(array (
'title' => $title1,
'metaDesc' => $metaDesc,
'metaKeywords' => $metaKeywords,
'navContent' => $navContent,
'leftContent' => $leftContent,
'defaultContent' => $module_content,
'rightContent' => $rightContent,
'footerContent' => $copyright
));
但樹枝呈現在這種情況下也rightContent的HTML,即使心不是任何內容:
默認情況下並沒有在上面我呈現這樣加載任何的4個模板。
此:http://twig.sensiolabs.org/doc/recipes.html? – hakre
對不起,這不是我的意思。我只是想告訴TWIG它應該加載什麼樣的模板。我不想告訴TWIG。 – HenryW
現在在你的代碼中,你根本不會加載任何*模板。你真的知道你將如何加載一個特定的模板? – hakre