6
如何創建一個可以在多個模板頁面間重複使用的html片段,並且可以將變量s傳入?一些像這樣的(但顯然有點複雜):Drupal - 呈現模板中的子視圖/部分
<ul>
<? foreach ($items as $item): ?>
<li><?=$item?></li>
<? endfor; ?>
</ul>
感謝
如何創建一個可以在多個模板頁面間重複使用的html片段,並且可以將變量s傳入?一些像這樣的(但顯然有點複雜):Drupal - 呈現模板中的子視圖/部分
<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'));