【问题标题】:How to apply a theme to a Drupal function?如何将主题应用于 Drupal 功能?
【发布时间】:2012-06-09 22:02:26
【问题描述】:
我有一个名为 _home() 的 Drupal 7 函数,由 home URL 调用。
在这个函数中,我想生成 HTML 输出并返回它。我需要向用户显示生成的 HTML。实际上,我在函数中嵌入了 HTML 标签(div、tables、b...)并返回给用户。它运行,但我认为必须有更好的方法来做到这一点,也许使用模板或主题。
有没有办法将模板应用于_home 函数,即使它不是节点/另一个 Drupal 对象?
【问题讨论】:
标签:
drupal-7
drupal-theming
drupal-templates
【解决方案1】:
if the "home" url is being created using modules then the following might be useful for you.
In your module file create
function modulename_theme($existing, $type, $theme, $path)
{
$theme_hooks = array(
'home' => array(
'template' => 'home',//name of template file will be home.tpl.php
'path' => $path . '/templates',
'variables' => array(
),
));
return $theme_hooks;
}
//As _home is the callback function for "home" url
function _home($node)
{
return theme('home', array('node' => $node));
}
Now under your module create a templates folder & in that create home.tpl.php & place your html in that file..