我想得到一个very使用 drupal 的 hook_theme() 加载模板文件的简单模块。这几乎和你想象的一样简单。
function sectionheader_theme ( $existing, $type, $theme, $path ) {
return array(
'sectionheader' => array(
'variables' => array( 'foo' => NULL ),
'template' => 'sectionheader',
),
);
}
该模板名为sectionheader.tpl.php。该模块的其余部分按预期工作。我已经清除了 Drupal 缓存。我在这个函数中插入了一个 die("Debug") 语句,它is正在执行,但我的模板根本没有被调用。该模板仅包含一些调试文本,因此我可以看到它正在工作,但在模块的任何视图中都不可见。
我已经完成了我能找到的每个示例中的所有操作,我什至直接从其他模块复制并粘贴了代码,但该模板仍然无法加载。
请注意,如果您已将模板文件放在模块目录中的 /theme 子文件夹中(这是最佳实践),您还需要在 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'
),
);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)