Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Pass array() as argument to a function from within a tpl?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
Josh
Smarty n00b


Joined: 19 Sep 2005
Posts: 1

PostPosted: Mon Sep 19, 2005 1:42 pm    Post subject: Pass array() as argument to a function from within a tpl? Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Sep 19, 2005 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
wieza
Smarty Rookie


Joined: 18 May 2006
Posts: 10

PostPosted: Thu Apr 05, 2007 10:00 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Apr 05, 2007 9:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP