2012-10-20 4 views
10

나는 새로운 드루팔 7 테마를 생성하고이 같은 template.php에서 hook_theme을 구현하기 위해 노력 : drupal 7에서 hook_theme을 구현하는 방법은 무엇입니까?

function mytheme_theme($existing, $type, $theme, $path){ 
    return array(
     'mytheme_header'=>array(
      'template'=>'header', 
      'path'=>$path.'/templates', 
      'type'=>'theme', 
     ), 
    ); 
} 

는 내가 템플릿 디렉토리에 header.tpl.php을 배치하고 모든 캐시를 삭제하고, 테마 함수를 호출

theme('mytheme_header', $vars); 

및 header.tpl.php이 추천했습니다 :

<?php 
fb('calling header template');//the function of FirePHP to output debug info 
print '<div>Header</div>'; 
//... 

내가 방화범 확인하고이 정보를 '헤더 템플릿 호출'을 얻을, 그것은 의미 그것은 header.tpl.php를 호출했지만 html 코드를 출력하지 않았습니다. 내 코드에 무슨 문제가 있습니까?

답변

16

시도가 header.tpl.php 파일에서 hook_theme

function mytheme_theme($existing, $type, $theme, $path){ 
    return array(
     'mytheme_header' => array(
      'template' => 'header', 
      'path' => $path . '/templates', 
      'type' => 'theme', 
      'variables' => array(
       'title' => NULL, 
       'some_text' => NULL, 
      ), 
     ), 
    ); 
} 

variables 배열을 추가 :

<h1><?php print $title; ?></h1> 
<p><?php print $some_text; ?></p> 

을 그리고, 이런 식으로 그것을 밖으로 인쇄 :

$vars = array(); 
$vars['title'] = "This is a title"; 
$vars['some_text'] = "Some text..."; 
print theme('mytheme_header', $vars); 
+1

'arguments'은 이름이 바뀌 었습니다 드루팔 (Drupal 7의 변수들) – Clive

+0

감사. 나는 그것을 고쳤다. :) –

+0

변수의 문제가 아니 었습니다. 나는 FirePHP로 디버깅을했고, header.tpl.php를 발견했지만 html 코드를 출력하지 못했다. –

관련 문제