【发布时间】:2012-04-05 20:12:40
【问题描述】:
如何创建一个 html sn-p,我可以在多个模板页面中重复使用,并且可以将变量 s 传递到其中?有些像这样(但显然有点复杂):
<ul>
<? foreach ($items as $item): ?>
<li><?=$item?></li>
<? endfor; ?>
</ul>
谢谢
【问题讨论】:
如何创建一个 html sn-p,我可以在多个模板页面中重复使用,并且可以将变量 s 传递到其中?有些像这样(但显然有点复杂):
<ul>
<? foreach ($items as $item): ?>
<li><?=$item?></li>
<? endfor; ?>
</ul>
谢谢
【问题讨论】:
在自定义模块中使用hook_theme(),然后在您的模板中调用theme() 方法。
在你的模块中:
mymodule_theme($existing, $type, $theme, $path) {
return array(
'my_theme_name' => array(
'template' => 'my_template_file_name', // without the .tpl.php extension
'variables' => array(), // to define default values for passed variables
)
);
}
在您的模板中:
theme('my_theme_name', array('arg1' => 'val1', 'arg2' => 'val2'));
【讨论】: