How can I create a html snippet that I can reuse across multiple template pages and can pass variable s into? Some like this (but obviously a bit more complicated):
<ul>
<? foreach ($items as $item): ?>
<li><?=$item?></li>
<? endfor; ?>
</ul>
Thanks
Use hook_theme()
in a custom module, then call the theme()
method from within your template.
In your module:
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
)
);
}
In your template:
theme('my_theme_name', array('arg1' => 'val1', 'arg2' => 'val2'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With