|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Josh Smarty n00b
Joined: 19 Sep 2005 Posts: 1
|
Posted: Mon Sep 19, 2005 1:42 pm Post subject: Pass array() as argument to a function from within a tpl? |
|
|
Hi all
I've got the following problem...
I have an object called 'site' that has the method 'getUrl()'. This method can take an associative array as argument, so I can call it like this:
Code: | $site->getUrl(array(
'key1' => 'value1'
,'key2' => 'value2'
...
)); |
Now I'd like to call this method from within a template...
Code: | <a href="{$site->getUrl(array('key1' => 'value1','key2' => 'value2'))}">Link</a> |
But there Smarty tells me 'syntax error: unrecognized tag'...
What can be done here? Is the support for creating arrays as a parameter missing in Smarty? Or did I miss something?
Thanks and greets
Josh |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 19, 2005 2:21 pm Post subject: |
|
|
That syntax won't work, you can only pass strings or variables:
Code: | <a href="{$site->getUrl($params))}">Link</a> |
Another option would be a wrapper function:
Code: | {geturl key1="value1" key2="value2"} |
|
|
Back to top |
|
wieza Smarty Rookie
Joined: 18 May 2006 Posts: 10
|
Posted: Thu Apr 05, 2007 10:00 am Post subject: |
|
|
Hi. Since last post in this topic it has passed neraly 2 years, so i would like to ask if something has changed in smarty and is ist now possible to pass array? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Apr 05, 2007 9:15 pm Post subject: |
|
|
Nothing has changed in that regard. Smarty does not have array literals. Thus you can not pass an array literal, but as before, you can pass variables that are arrays. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|