【问题标题】:Drupal 7 is ignoring my theme_hook_suggestionsDrupal 7 忽略了我的 theme_hook_suggestions
【发布时间】:2014-09-16 17:54:49
【问题描述】:

在这里慢慢失去理智:

我需要为某个词汇的术语制作一个模板。我创建了一个子主题并尝试使用 theme_preprocess_page() (theme_preprocess_taxonomy_term() 不知何故从未被调用)。

template.php

function aura_sub2_preprocess_page(&$variables) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $term = taxonomy_term_load(arg(2));
    drupal_set_message( 'page__vocabulary__' . $term->vocabulary_machine_name );
    $variables['theme_hook_suggestions'][0] = 'page__vocabulary__' . $term->vocabulary_machine_name;
  }
}

如您所见,我什至覆盖了第一个用于测试目的的建议,但它没有任何改变。页面加载就像什么都没发生一样。 当我打开“mydomain.com/?q=en/myvocabulary/someterm”时,我收到状态消息“page__vocabulary__myvocabulary”。到目前为止一切顺利,但模板建议似乎被忽略了。 该模板位于该子主题的“主题”目录中。我尝试了“--”和“__”的所有可能组合,但无济于事。模板只包含这个,有问题吗?:

主题/页面--vocabulary--myvocabulary.tpl.php

<h1>MYVOCAB TEST</h1>

缓存每次都清空,没有变化。 :c

有什么想法吗?

【问题讨论】:

    标签: drupal drupal-7 drupal-themes


    【解决方案1】:

    我认为这可能是因为您将建议添加到数组的开头而不是结尾。
    替换:

    $variables['theme_hook_suggestions'][0] = 'page__vocabulary__' . $term->vocabulary_machine_name;
    

    与:

    $variables['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
    

    【讨论】:

    • 不幸的是,这不起作用。当然这是正确的做法。
    • 你的预处理函数真的被调用了吗?
    • 是的,检查我是否设置了显示在页面上的状态消息。状态消息还告诉函数放入列表中的建议。所以这一切看似有效,但对页面的渲染没有任何影响。
    • 模板文件名是什么?你100%确定它是正确的吗?并且它在正确的文件夹中?
    • 不确定,我尝试了“page--vocabulary--myvocabulary.tpl.php”的所有可能的单破折号/-下划线和双破折号/-下划线组合。它位于“主题”文件夹中。应该是这样吗?
    猜你喜欢
    • 1970-01-01
    • 2023-02-12
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 2017-05-05
    • 2011-12-22
    • 2017-12-09
    • 2018-09-08
    相关资源
    最近更新 更多