我是 drupal 新手...
我有不同类型的内容,如新闻、事件等,它们的内容也不同。新闻详细信息页面有标题-内容文本-日期。但事件详细信息页面有标题-日期-内容文本-位置-演讲者等。所以我需要针对这些不同类型的不同布局页面。因此,我启用了 Drupal Themer 来获取候选名称。对于事件页面,它给了我 page-node.tpl.php ,它也为新闻页面提供了相同的信息:(我如何分离这些页面?我期望像 page-event- node.tpl ,但没有...:/Drupal Themer 还为事件页面提供了唯一的候选名称,例如 page-node-18.tpl.php 但这并不意味着任何事情,因为我可以不通过此节点名称为所有事件创建通用布局。:(
感谢有很大帮助!!非常感谢!!!
最佳答案
虽然按照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;
}
}
完成此操作后,您应该能够添加例如一个“page-type-event.tpl.php”文件,该文件应用于所有事件节点页面。
(注意:添加该函数后,您需要 trigger a rebuild of the theme registry 才能被系统识别)
关于德鲁帕尔 6 : Drupal Themer gives same candidate name for different type of content types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2964811/