建立node-1.tpl.php这样的模板

在使用drupal建站时,可能会遇到单独定制某个节点模板的需要,(例如想建立node-1.tpl.php这样的模板)在drupal.org找到了相关的解决办法。

需要复制或合并代码到你的主题模板的template.php
drupal 6.x

<?php
function phptemplate_preprocess_node(&$vars) {
    $vars['template_files'][] = 'node-' . $vars['nid'];
    return $vars;
}
?>

Drupal 4.7.x 和 Drupal 5.x

<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'node':
      $vars['template_files'] = array('node-'. $vars['nid']);
      break;
  }
  return $vars;
}
?>

然后复制node.tpl.php另存为:node-[nodeID].tpl.php (例如:node-1.tpl.php)根据自己的需要修改。 原文链接:Separate node template for a specific node

由于blogger被无期限“和谐”,故将此文转了过来。
原文:http://playts.blogspot.com/2009/02/node-1tplphp.html

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <img> <em> <del> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6>
  • 自动断行和分段。
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.