2012-06-09 29 views
1

我有一個名爲_home()的Drupal 7函數,它由'home'url調用。如何將主題應用於Drupal功能?

在這個函數中,我想生成html輸出,並返回它,我需要顯示生成的HTML給用戶。實際上,我在函數中嵌入了html標籤(div,tables,b ...)並返回給用戶;它運行,但我認爲必須有更好的方式來做到這一點,也許使用模板或主題。 有沒有辦法將模板應用到_home函數,即使它不是節點/其他Drupal對象?

回答

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.. 
+0

太好了,非常感謝! – Cris