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

问题描述

我在一个模块的 hook_preprocess_page()实现中建议一个模板文件,但建议的模板文件似乎不被使用。



模板文件是page-terminal-template.tpl.php,它在包含该模块的目录中,这是执行 hook_preprocess_page()

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

有人可以帮助我吗?

解决方案

实际上,这个钩子也可以从主题的template.php文件以及模块的钩子中调用。



请参考Drupal 7文档这里

 

code>函数MY_THEME_preprocess_page(& $ variables){
if(arg(0)==terminal){
$ variables ['theme_hook_suggestions'] [] =page__terminal_template

}
}

模板建议将工作。



编辑:此功能也可以使用模块使用钩子实现。


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.

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";
  }
}

Could anyone please help me?

解决方案

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

Please refer Drupal 7 documentation here.

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";

  }
}

And the template suggestions will work.

Edit: This functionality can also be implemented with Modules using hooks.

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

08-22 23:30