hook_preprocess_page() 似乎没有使用建议的模板文件 [英] hook_preprocess_page() does not seem to use the suggested template file

查看:20
本文介绍了hook_preprocess_page() 似乎没有使用建议的模板文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建议在从模块完成的 hook_preprocess_page() 实现中使用模板文件,但似乎没有使用建议的模板文件.

I am suggesting a template file in the hook_preprocess_page() implementation done from a module, but the suggested template file doesn't seem to be used.

模板文件是page--terminal-template.tpl.php,在包含模块的目录下,这是hook_preprocess_page()的实现.

The template file is page--terminal-template.tpl.php, which is in the directory containing the module, and this is the implementation of hook_preprocess_page().

function terminal_preprocess_page(&$variables) {
  if (arg(0) == "terminal") {
    $variables['theme_hook_suggestions'][] = "page__terminal_template";
  }
}

谁能帮帮我?

推荐答案

其实这个hook也可以从主题的template.php文件中和module的hook一起调用.

Actually, this hook can also be called from theme's template.php file along with module's hook.

请参考 Drupal 7 文档这里.

Please refer Drupal 7 documentation here.

如果你的活动主题是 MY_THEME,那么代码应该是:

Say if your active theme is MY_THEME, then the code should be:

function MY_THEME_preprocess_page(&$variables) {
  if (arg(0) == "terminal") {
      $variables['theme_hook_suggestions'][] = "page__terminal_template";

  }
}

模板建议将起作用.

此功能也可以通过使用钩子的模块来实现.

This functionality can also be implemented with Modules using hooks.

这篇关于hook_preprocess_page() 似乎没有使用建议的模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆