0

header, footer 및 content 영역이있는 page.tpl.php가 있습니다. 모듈에서 hook_menu에 다른 내용 기반을로드해야합니다. 내가drupal에서 theme()이 프린트되지 않습니다.

이 다음은 모듈 폴더에 템플릿 tutorial.tpl.php이

function my_module_theme() { 
    return array(
    'tutorials_test' => array(
    'template' => 'tutorial' 
    ) 
); 
} 

:

나는 시도하고 내 템플릿에서 인쇄 뭔가 모듈에 다음 테스트 코드를 사용하고 내 hook_menu 및 콜백 함수

function my_module_menu() { 
     $items['insights/tutorials'] = array(
     'title' => 'Tutorials', 
     'access callback' => TRUE, 
     'page callback' => 'insights_tutorials' 
); 
} 

콜백 함수

function insights_tutorials() { 
    echo 'test'; 
    print theme('tutorials_test'); 
    echo 'after test'; 
    } 

내가 그 페이지를 볼 때 'test'와 'after test'라는 텍스트를 볼 수는 있지만 템플릿의 내용은 인쇄되지 않습니다. 당신의 hook_theme 구현 내부

<h1>Hello World</h1> 

답변

1

(기능 my_module_theme)는 variables

function my_module_theme() { 
    return array(
    'tutorials_test' => array(
     'template' => 'tutorial', 
     'variables' => array(// the variables key 
      'title' => NULL, 
      'details' => NULL, 
     ), 
    ) 
); 
} 

그리고 출력 할 HTML과 같은 전달해야합니다

tutorial.tpl.php이 간단한 코드가 그 :

print theme('tutorials_test', array(
    'title' => 'This is the title', 
    'details' => 'And this is details', 
)); 

hook_theme()을 구현하는 방법은 this answer을 살펴보십시오.

희망이 작동 ... 무하마드.

+0

이것은 작동하지 않습니다. 같은 문제 – Abhishek

+0

마지막 줄에 제공된 답을 확인하십시오. 그리고 변경 한 후에는 캐시를 플러시하는 것을 잊지 마십시오. –

+0

예 정확히 했음 – Abhishek