Drupal 7重写node.tpl.php

时间:2015-07-28 04:10:54

标签: drupal-7 override nodes

我正在尝试覆盖首页节点,但是在遵循官方网站的指南后,它无法正常工作。

指南:https://www.drupal.org/node/1585528

我已将node.tpl.php重命名为node--front.tpl.php,并对布局,已保存和已清除的缓存进行了更改。没有显示更改。

现在如果我直接编辑node.tpl.php它会显示更改,任何人都知道我在覆盖特定节点模板时做错了什么?

修改 我想将标题移到首页显示的图像下方。

见下文:在内容块下移动标题栏,按照我的意愿移动标题,但是如何仅为首页而不是所有节点指定? (将node.tpl.php重命名为node--front.tpl.php无效,如上所述)

在node.tpl.php中:(标题栏)

<?php print render($title_prefix); ?>
<?php if (!$page): ?>
  <h2<?php print $title_attributes; ?>>
    <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
  </h2>
<?php endif; ?>
<?php print render($title_suffix); ?>

(内容块)

<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
  // We hide the comments and links now so that we can render them later.
  hide($content['comments']);
  hide($content['links']);
  print render($content);
?>

2 个答案:

答案 0 :(得分:1)

要覆盖特定节点的节点模板,您需要覆盖默认的node.tpl.php。对于此副本,将现有的node.tpl.php文件复制到节点 - {node_id} .tpl.php。

如果您只想覆盖首页的页面模板,那么您可以创建page-front.tpl.php文件并复制page.tpl.php文件,然后根据您的要求进行修改。

仍有问题,然后在template.php中使用hook_preprocess_page()并使用dpm()函数查找将给出模板文件执行顺序的theme_suggestions。

答案 1 :(得分:0)

您可以使用node- {nodeid} .tpl.php

它可能对你有帮助。

来源:https://drupal.stackexchange.com/questions/39710/how-do-i-define-a-template-file-for-a-specific-node-id

由于 Samit K

samitkhulve.com

相关问题