简体   繁体   English

如何在Drupal 6中为不同的节点添加不同的模板

[英]How to add different template for different nodes in Drupal 6

I have 3 nodes in my sites. 我的站点中有3个节点。

  1. node/1 - Login node / 1-登录
  2. node/2 - Contact 节点/ 2-联系人
  3. node/3 - Register 节点/ 3-注册

I want to have different template for different nodes. 我想为不同的节点使用不同的模板。 If I do as page-node-1.tpl.php , page-node-2-tpl.php , its for the entire page, I don't want that , I want specifically override for node content. 如果我对整个页面都使用page-node-1.tpl.php,page-node-2-tpl.php,则不需要这样做 ,我想专门覆盖节点内容。

I have already tried the following links:- 我已经尝试了以下链接:

I am using Drupal 6 我正在使用Drupal 6

I have not used Drupal 6 in a while, but from what I realized, Drupal 6's default node templates will not have a node ID based template suggestion. 我已经有一段时间没有使用Drupal 6了,但是据我所知,Drupal 6的默认节点模板不会包含基于节点ID的模板建议。

That does not mean you cannot do it from a custom theme. 这并不意味着您无法通过自定义主题进行操作。

<?php

function THEMENAME_preprocess_node(&$vars) {
    $vars['template_files'][] = 'node-' . $vars['nid'];
}

?>

In your theme's template.php, add the above code, replacing the theme name (or merge the function contents if you already have that function). 在主题的template.php中,添加上面的代码,替换主题名称(或者如果已有功能,则合并功能内容)。 This will make the Drupal check for node-123.tpl.php file ( 123 being an example node ID), and will use it for in place of node.tpl.php . 这将使Drupal检查node-123.tpl.php文件( 123是示例节点ID),并将其用于代替node.tpl.php

Since you mentioned you'd be using node/1 or any node contents to embed a login form, let me tell you that this isn't exactly a good idea. 既然您提到过要使用node/1或任何节点内容来嵌入登录表单,所以让我告诉您,这并不是一个好主意。 The login form needs to be accessible when the site is in maintenance mode, and it can be hard to manage them later with different deployment environments. 当站点处于维护模式时,需要访问登录表单,以后使用不同的部署环境可能很难管理登录表单。 This part is completely irrelevant to the question though. 这部分与问题完全无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM