Hey, I was wondering if it was possible to pass an associative array as a parameter in a custom function. This is my scenario:
In the php file I set the array:
$dataArr = array('one'=>'1','two'=>'2','three'=>'3');
$tpl->assign('dataArr',$dataArr);
This is my custom function dulled down
function smarty_function_drawChart($params, &$smarty){
print_r($params);
}
This is my function call in the template
{drawChart data={$dataArr} title='Title of the Chart'}
The problem I am having is that if you notice where I print_r($params), that shows:
Array
(
[data] => Array
[title] => Title of the Chart
)
It seems to be passing the string 'Array' rather than the actual array. I have done debugging right before passing the $dataArr that shows {$dataArr.one} has a value. Once inside my custom function $params['data'].one does not exist.
Any ideas on what I am doing wrong?
Thanks
Levi
I am still not 100% sure why my code above didn't work. My thought is that the brackets work just as an 'echo' would do in php, which is why the string 'Array' was being passed into the function. I was able to get it to work by simple removing the brackets around the $dataArr variable.
This was my original call:
{drawChart data={$dataArr} title='Title of the Chart'}
This is my new call that works
{drawChart data=$dataArr title='Title of the Chart'}