With Smarty 3.0, I would like to do, in order to avoid code repetition:
{$assocArray = ['param1' => 'value1', 'param2' => 'value2', ...]}
{magicFunction name='someHelper' params=$assocArray}
instead of
{$assocArray = ['param1' => 'value1', 'param2' => 'value2', ...]}
{someHelper param1=$assocArray['value1'] param2=$assocArray['value2'] ...}
I’ve found {call} but is not exactly what I’m looking for.
I will try to do it myself, but I’m open to suggestions (or even a code snippet to copy/paste :-p)
You could create a wrapper function named
unroll_parametersdefined as below.That will make you able to use the following:
If you’d like to access
$smartyinside the called function, append the value to$params['args']before callingcall_user_func_array.Note: If the function declaration is like:
function foo ($var1,$var2, ..., $smarty)