如何将主题应用于Drupal函数?

时间:2012-06-09 22:02:27

标签: drupal-7 drupal-theming drupal-templates

我有一个名为_home()的Drupal 7函数,由'home'URL调用。

在这个函数中,我想生成html输出,并返回它,我需要向用户显示生成的html。实际上我在函数内部嵌入了html标签(div,tables,b ......)并返回给用户;它运行,但我认为必须有一个更好的方法来做到这一点,也许使用模板或主题。 有没有办法将模板应用于_home函数,即使它不是节点/其他Drupal对象?

1 个答案:

答案 0 :(得分:2)

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..
相关问题