如何创建一个 html 片段,我可以在多个模板页面中重复使用,并且可以将变量 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'));
关于php - Drupal - 在模板中呈现 subview /部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802422/