首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Drupal 7:未加载适当的页面模板

Drupal 7:未加载适当的页面模板
EN

Stack Overflow用户
提问于 2013-07-17 03:20:42
回答 1查看 328关注 0票数 0

该页面的路径别名是/年度报告/2012。我在主题template.php文件中设置了以下内容:

代码语言:javascript
复制
function tcm_preprocess_page(&$variables, $hook) {
    $alias = drupal_get_path_alias($_GET['q']);
    $alias = explode('/', $alias);
    $template_filename = 'page';
    foreach ($alias as $path_part) {
      if(is_numeric($path_part)){
          $variables['theme_hook_suggestions'][] = $template_filename . '__%';
      }
      $template_filename = $template_filename . '__' . $path_part;
      $variables['theme_hook_suggestions'][] = $template_filename;
    }
    print_r("<!--\n");
    print_r($variables['theme_hook_suggestions']);
    print_r("\n-->\n");
}

当我加载页面时,它没有加载正确的模板。如果您注意到,我正在将suggestions数组输出到注释,以确保建议适当的模板。它输出以下内容:

代码语言:javascript
复制
<!--
Array
(
    [0] => page__node
    [1] => page__node__%
    [2] => page__node__207
    [3] => page__annual-reports
    [4] => page__annual-reports__%
    [5] => page__annual-reports__2012
)

-->

我有一个名为page--年度报告--%.tpl.php的模板文件。但是,它加载的是基页--node.tpl.php。我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-17 03:46:38

好的。问题是模板预处理器中所有的'-‘字符都需要替换为'_’,而不仅仅是别名路径部分之间的字符。因此,“年度”和“报告”之间的“-”也必须被替换。所以我的预处理器中的for循环现在看起来像这样:

代码语言:javascript
复制
foreach ($alias as $path_part) {
  if(is_numeric($path_part)){
    $variables['theme_hook_suggestions'][] = $template_filename . '__%';
  }
  $template_filename = $template_filename . '__' . preg_replace("/-/", "_", $path_part);
  $variables['theme_hook_suggestions'][] = $template_filename;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17685225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档