Drupal 7 - 如何从模块加载模板文件? [英] Drupal 7 - How to load a template file from a module?
本文介绍了Drupal 7 - 如何从模块加载模板文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我创建了一个名为'moon'的简单模块
function moon_menu(){
$ items = array();
$ items ['moon'] = array(
'title'=>'',
'description'=> t('Detalle de un Programa'),
'page callback'=>'moon_page',
'access arguments'=> array('access content'),
'type'=> MENU_CALLBACK
);
return $ items;
}
函数moon_page(){
$ id = 3;
$ content ='aa';
}
在moon_page()函数中,我喜欢加载自定义模板'moon.tpl.php'从我的主题文件。
这是可能吗?
解决方案
对于您自己的东西(不覆盖另一个模块的模板)?
当然,您只需要:
-
使用 hook_theme()
-
调用主题('moon',$ args)
$ args是一个数组,您的hook_theme()实现指定的模板。
I am trying to build my own module in Drupal 7.
So I have created a simple module called 'moon'
function moon_menu() {
$items = array();
$items['moon'] = array(
'title' => '',
'description' => t('Detalle de un Programa'),
'page callback' => 'moon_page',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
return $items;
}
function moon_page(){
$id = 3;
$content = 'aa';
}
in moon_page() function, I like to load a custom template 'moon.tpl.php' from my theme file.
is this possible?
解决方案
For your own stuff (not overriding a template from another module)?
Sure, you only need to:
Register your template with hook_theme()
Call theme('moon', $args)
$args is an array that contains the arguments to the template as specified by your hook_theme() implementation.
这篇关于Drupal 7 - 如何从模块加载模板文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文