按照monkeyninja(+1)的建議使用不同的node.tpl.php文件將是「正常」的方式,您可以通過自己添加基於節點類型的頁面模板建議來添加所需的功能,在preprocess_page
function在一個自定義模塊/主題內:
function yourModuleOrTheme_preprocess_page(&$variables) {
// If this is a node page, add a page template suggestion based on node type
if (isset($variables['node'])) {
// Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
$suggestion = 'page-type-' . $variables['node']->type;
// Add to end of suggestion array, thus keeping the fallback to other suggestions,
// if this specific version is not implemented by the theme
$variables['template_files'][] = $suggestion;
}
}
有了這個,你應該可以添加eg 'page-type-event.tpl.php'文件,應該用於所有事件節點頁面。
(注:補充說,功能得到它被系統識別後,您將需要trigger a rebuild of the theme registry)
哇!感謝您的回覆!它對我的解決方案看起來不錯...所以我將這個函數添加到themes/mysite/template.php,以及如何使用它來定義頁面類型event.tpl.php到事件頁面? ps,感謝您的鏈接http://drupal.org/node/223430我正在閱讀所有內容。 – 2010-06-03 10:56:40
你是主人!忘了清除緩存,現在它工作得非常棒!現在我有page-type-event.tpl.php!謝啦!我是認真的!!我很樂意爲你買一杯啤酒或任何東西...... :) – 2010-06-03 11:01:33
很高興能有所幫助 - 一個警告的話,儘管如此:將頁面模板過度疊加可能會成爲相當的維護負擔,因爲你最終會多個地方你需要保持同步的基本東西,應該是相同的整個網站。因此,您可能仍然希望探索替代解決方案,如建議的上下文模塊或基於節點類型的切換塊可見性等... – 2010-06-03 11:09:59