Drupal中节点的标准模板是node.tpl.php
可以为内容类型调用不同的模板,例如“newsitem”。你会这样称呼:node-newsitem.tpl.php
。
我想知道是否有办法调用特定的节点ID? node-34.tpl.php
不工作。
由于
答案 0 :(得分:6)
答案 1 :(得分:3)
在主题的template.php中,将以下内容放在theme_preprocess_node()的顶部:
$vars['template_files'][] = 'node-'. $vars['node']->nid;
因此,如果您的主题名为“myTheme”,则可能包含以下内容:
function myTheme_preprocess_node(&$vars){
$vars['template_files'][] = 'node-'. $vars['node']->nid;
}
答案 2 :(得分:0)
我说话的时候有这个工作。在Drupal 6中,我的首页是节点5.它使用
页节点-5.tpl.php
如果没有加载,请考虑清除缓存或重建主题注册表。
答案 3 :(得分:-1)
该命名约定将起作用,而不是默认情况下。假设这是Drupal 6,请尝试将以下代码添加到主题的template.php:
/**
* Override or insert variables into the node templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*/
function yourthemename_preprocess_node(&$vars, $hook) {
$node = $vars['node'];
$vars['template_file'] = 'node-'. $node->nid;
}
确保您没有尝试重新声明yourthemename_preprocess_node()
- 也就是说,如果它已存在于您的主题的template.php中,只需添加$ node和$ vars ['template_file']行。