2012-06-09 3 views
1

'home'URL에 의해 호출되는 _home()이라는 Drupal 7 함수가 있습니다.Drupal 함수에 테마를 적용하는 방법은 무엇입니까?

이 함수에서 html 출력을 생성하고 그것을 반환하려면 결과 html을 사용자에게 표시해야합니다. 사실 나는 HTML 태그 (div, 테이블, b ...)를 함수 내에 포함하고 사용자에게 반환합니다. 그것은 실행하지만 더 나은 방법, 어쩌면 템플릿이나 테마를 사용하여 그것을해야한다고 생각합니다. 노드/다른 Drupal 객체가 아니더라도 _home 함수에 템플릿을 적용 할 수 있습니까?

답변

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