php smarty append plugin?

chronoel

New member
hi i made a smarty function plugin that appends data to an array. i know i could do the appending in php but i still opted to create the plugin for smarty because i have some design logic which needs me to append some data to an array. the code for the plugin is shown below:

function smarty_function_append($params, &$smarty)
{
if (empty($params['var'])) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (!in_array('value', array_keys($params))) {
$smarty->trigger_error("assign: missing 'value' parameter");
return;
}

$smarty->append($params['var'], $params['value']);
}

shown below is a sample usage of the plugin as shown below:

{append var=arrayVar value="foo"}

but everytime i use it, it appends the data twice. so the resulting content of the array would be:

Array {
[0] => foo
[1] => foo
}

and if i try to use it again. i appends the new data twice.

{append var=arrayVar value="bar"}

Array {
[0] => foo
[1] => foo
[2] => bar
[3] => bar
}

what's the problem with my plugin? can you please help me figure out why this is happening?

thanks!
 
Back
Top