drupal 7 hook_theme()不加载模板文件 [英] Drupal 7 hook_theme() not loading template file

查看:181
本文介绍了drupal 7 hook_theme()不加载模板文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 简单的模块来加载使用drupal的hook_theme()的模板文件。这很简单,你可以想像。

I'm trying to get a very simple module to load a template file using drupal's hook_theme(). It's pretty much as simple as you can possibly imagine.

function sectionheader_theme ( $existing, $type, $theme, $path ) {
  return array(
    'sectionheader' => array(
      'variables' => array( 'foo' => NULL ),
      'template' => 'sectionheader',
    ),
  );
}

模板命名为sectionheader.tpl.php。模块的其余部分按预期工作。我已经清除了Drupal缓存。我已经在这个函数中插入了一个die(Debug)语句,而且它正在执行 ,但我的模板根本就没有被调用。该模板只有一些调试文本,所以我可以看到它的工作,但在模块的任何视图中都不可见。

The template is named sectionheader.tpl.php. The rest of the module is working as expected. I've cleared the Drupal cache. I've inserted a die("Debug") statement in this function, and it is being executed, but my template is simply not being called, ever. The template merely has some debug text in it so I can see that it's working, but is not visible in any view of the module.

我已经做了一切例如我可以找到,我甚至直接从其他模块复制和粘贴代码,并且此模板仍然无法加载。

I've done everything in every example I can find, I've even copied and pasted code directly from other modules, and this template will still not load.

推荐答案

请注意,如果您将模板文件放在模块目录(这是最佳做法)中的/主题子文件夹中,则还需要在hook_theme中指定文件路径

Note, if you have put your template file in a /theme subfolder in your module dir ( which is best practice), you'll also need to specify the file path in hook_theme

function example_theme($existing, $type, $theme, $path) {
  return array(
    'example_function' => array(
      'variables' => array('var1' => array(), 'var2' => array(), 'var3' => array()),
      'template' => 'example-template',
      'path' => drupal_get_path('module', 'example').'/theme'
    ), 
  );  
}

这篇关于drupal 7 hook_theme()不加载模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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