Drupal 7 不使用模板建议
我已将以下内容添加到我的 template.php 文件中的 [themename]_preprocess_page 函数中:
<?php
if ($variables['is_front'])
{
$variables['theme_hook_suggestions'] = array();
$variables['theme_hook_suggestions'][] = 'page__index';
}
if (isset($variables['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $variables['node']->type);
}
如果我在 $variables 数组上运行 var_dump,我可以看到,在我的首页上,“theme_hook_suggestions”设置为仅使用'页面__索引'。我有一个名为“page--index.tpl.php”的文件。 Drupal 仍然使用 page.tpl.php。
我还注释掉了上面的代码,并将该文件重命名为“page--front.tpl.php”,它仍然使用page.tpl.php。每次更改后我都会清除缓存。
我缺少什么?
编辑:为了帮助澄清,我想覆盖前面页面的整个设计 - 没有列或侧边栏、不同的图形、某些 div 上的不同背景等。我不希望覆盖“node--”模板文件(尚未)。
最后,我需要一个与网站其他部分设计不同的静态首页,然后为每种内容类型提供一个自定义节点模板。
I have added the following to my template.php file, in the [themename]_preprocess_page function:
<?php
if ($variables['is_front'])
{
$variables['theme_hook_suggestions'] = array();
$variables['theme_hook_suggestions'][] = 'page__index';
}
if (isset($variables['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $variables['node']->type);
}
If I run a var_dump on the $variables array, I can see that, on my front page, the 'theme_hook_suggestions' is set to only use 'page__index'. I have a file named 'page--index.tpl.php'. Drupal still uses page.tpl.php.
I also commented out the code above, and renamed the file to 'page--front.tpl.php' and it still used page.tpl.php. I clear the caches after every change.
What am I missing?
Edit: To help clarify, I want to override the entire design of the page for the front - no columns or sidebars, different graphics, different backgrounds on some of the div's, etc. I don't want to override the 'node--' template files (yet).
In the end, I need to have a static front page with a different design than the rest of the site, then a custom node template for each content type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我与#drupal IRC 频道上的优秀人员一起工作并发现了这个问题。不确定这是代码中的错误还是故意的 - 但您不能使用“索引”一词来表示这些主题建议。我将内容类型的名称更改为“主页”,瞧!
I worked with the awesome folks on the #drupal IRC channel and found the issue. Not sure if this is a bug in the code or on purpose - but you cannot use the word 'index' for those theme suggestions. I changed the content type's name to 'homepage' and voila!