Php 不明白为什么hook_theme()不';我好像什么也没做
我正在使用Drupal7,并创建了一个名为Php 不明白为什么hook_theme()不';我好像什么也没做,php,drupal,drupal-7,drupal-theming,drupal-hooks,Php,Drupal,Drupal 7,Drupal Theming,Drupal Hooks,我正在使用Drupal7,并创建了一个名为fb的自定义模块。在fb.module文件中,我有以下内容: function fb_theme($existing, $type, $theme, $path) { return array( 'fb' => array( 'template' => 'fb' ) ); } 在与模块文件(模块的根目录)相同的目录中,我有一个名为fb.tpl.php的文件,其中包含: fb.tpl.php is work
fb
的自定义模块。在fb.module
文件中,我有以下内容:
function fb_theme($existing, $type, $theme, $path) {
return array(
'fb' => array(
'template' => 'fb'
)
);
}
在与模块文件(模块的根目录)相同的目录中,我有一个名为fb.tpl.php
的文件,其中包含:
fb.tpl.php is working!
出于测试目的,我的主题的html.tpl.php
文件在正文中调用以下内容:
<?php
$ouput = theme('fb');
print_r($output);
?>
但是,
print\r($output)
行不会生成任何内容。我希望它包含fb.tpl.php
文件的内容,或者可能包含一个数组,其中包含该文件的内容作为其参数之一的值。为什么不呢?在Drupal 7中根本不需要使用主题函数。而是创建如下所示的可渲染阵列:
$output = array(
'#theme' => 'fb'
);
drupal_render($output);
并按如下方式输出:
$output = array(
'#theme' => 'fb'
);
drupal_render($output);
这是在html.tpl.php文件中输出它的最简单方法。您使用的是drupal 6语法。D7语法如下所示:
function fb_theme($existing, $type, $theme, $path) {
return array(
'fb' => array(
'file' => 'fb'
)
);
}
请参阅此处的完整文档:
[编辑]-在对主题挂钩进行更改后,也不要忘记刷新主题缓存,否则您将看不到更改 他的语法是正确的。“file”键指定函数在其中实现的文件,而不是主题实现的模板文件在本例中,template的键是正确的,用于向Drupal发出它应该使用的tpl.php文件的信号。