1

我有一个由URL_home()调用的 Drupal 7 函数。home

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

4

1 回答 1

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..
于 2012-06-11T07:29:14.207 回答