A module can add its own template functions. Define a PHP function named smarty_function_ followed by the name you'll use in templates, in your module's include.php:
/**
* Show a greeting
* @param array $params Template parameters
* @param object $smarty Smarty object
* @return string
*/
function smarty_function_xxHello_greeting($params, $smarty)
{
if (empty($params['name'])) {
return jrCore_smarty_missing_error('name');
}
$out = 'Hello, ' . jrCore_entity_string($params['name']) . '!';
if (!empty($params['assign'])) {
$smarty->assign($params['assign'], $out);
return '';
}
return $out;
}Templates can then use:
{xxHello_greeting name=$profile_name}(module)_(name), so it can't clash with another module's.$params. Check required ones, and return jrCore_smarty_missing_error('name') when one is missing, like the core functions.assign, so templates can keep the result for later.jrCore_entity_string().echo it.For a function other skins may use, tell them to call it through {jrCore_module_function}, so their templates still work without your module.
See the Developer Guide chapter for building modules.