未使用自定义 Drupal 主题模板文件
我正在尝试组织我的主题文件夹,其中包含数十个视图的节点主题覆盖。基本上我有两种不同的风格,我希望它们看起来或多或少相同。
template.php 有没有办法可以做到这一点?最好的方法是什么?
我在主题的 hook_preprocess_node 函数中尝试了这段代码:
switch($vars['view']->name) {
case 'taxonomy_term' :
switch($vars['view']->current_display) {
case 'page' :
array_push($vars['template_files'], 'list-view');
default :
break;
}
break;
default :
break;
}
当我查看主题开发人员时,我可以看到那里的 list-view.tpl.php 文件,但它实际上并没有使用我的主题目录中的该文件。我缺少什么?
I am trying to organize my theme folder, which has node theming overrides for dozens of views. Basically I have two different styles and I want them all to look the same, more or less.
Is there a way in template.php that I can do this? And what is the best way?
I tried this code in my theme's hook_preprocess_node function:
switch($vars['view']->name) {
case 'taxonomy_term' :
switch($vars['view']->current_display) {
case 'page' :
array_push($vars['template_files'], 'list-view');
default :
break;
}
break;
default :
break;
}
And when I look in theme developer, I can see the list-view.tpl.php file there, but its not actually using that file from my theme directory. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您在 theme() 中看到的Drupal 只有在模板存在时才会实际使用 drupal_discover_template()。
您应该尝试弄清楚是否是这种情况。
drupal_discover_template()
对于各种模板调用返回的内容。它能找到吗?
如果不是:
drupal_discover_template()
中放置一些调试代码,以找出 Drupal 认为它不再是模板的位置。我的直觉告诉我,这是由于模板文件所在的子目录所致,但您尚未将其添加到
template_files
变量中:views/lists/some_list.tpl.php 与 some_list.tpl.php 不同。As you can see in theme() Drupal will only actually use a template if it exists according to drupal_discover_template().
You should try to figure out if that is the case.
drupal_discover_template()
returns for vairious template calls.Can it find it?
If not:
drupal_discover_template()
to find out where Drupal thinks it no longer is a template.My gut-feeling says that it is due to subdirectories where the template files reside, but which you have not added to the
template_files
variable: views/lists/some_list.tpl.php is not the same as some_list.tpl.php.您需要重建缓存才能获取 tpl.php 文件。
You need to rebuild the cache for the tpl.php file to be picked up.