Drupal 7 - 如何从模块加载模板文件? [英] Drupal 7 - How to load a template file from a module?
本文介绍了Drupal 7 - 如何从模块加载模板文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Drupal 7 中构建我自己的模块.
I am trying to build my own module in Drupal 7.
所以我创建了一个名为moon"的简单模块
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';
}
在moon_page() 函数中,我喜欢从我的主题文件中加载自定义模板moon.tpl.php".
in moon_page() function, I like to load a custom template 'moon.tpl.php' from my theme file.
这可能吗?
推荐答案
对于你自己的东西(不是覆盖另一个模块的模板)?
For your own stuff (not overriding a template from another module)?
当然,您只需要:
使用 hook_theme()
调用主题('moon', $args)
Call theme('moon', $args)
$args 是一个数组,其中包含 hook_theme() 实现指定的模板参数.
$args is an array that contains the arguments to the template as specified by your hook_theme() implementation.
这篇关于Drupal 7 - 如何从模块加载模板文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文