【发布时间】:2010-08-10 15:15:42
【问题描述】:
Drupal 中节点的标准模板是node.tpl.php
可以为内容类型调用不同的模板,例如“newsitem”。你会这样称呼它:node-newsitem.tpl.php。
我想知道是否有办法调用特定的节点 ID? node-34.tpl.php不起作用。
谢谢
【问题讨论】:
Drupal 中节点的标准模板是node.tpl.php
可以为内容类型调用不同的模板,例如“newsitem”。你会这样称呼它:node-newsitem.tpl.php。
我想知道是否有办法调用特定的节点 ID? node-34.tpl.php不起作用。
谢谢
【问题讨论】:
【讨论】:
在您的主题的 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;
}
【讨论】:
正如我们所说,我正在工作。在 Drupal 6 中,我的首页是节点 5。它使用
page-node-5.tpl.php
如果没有加载,请考虑清除缓存或重建主题注册表。
【讨论】:
该命名约定将起作用,但不是默认情况下。假设这是 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'] 行添加到它。
【讨论】: