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

Assigning function output to variable.

 
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 -> General
View previous topic :: View next topic  
Author Message
digimatt
Smarty n00b


Joined: 13 Jan 2005
Posts: 2

PostPosted: Fri May 20, 2005 3:52 am    Post subject: Assigning function output to variable. Reply with quote

I appologize if this has been answered somewhere already. I couldn't find it.

Is it possible to assign the output of a function to a variable from within a template?

For example (I know this code won't work):

{assign var='stuff' value={my_func param1=this param2=that}}


I can't figure this one out. Any help much appreciated.
Back to top
View user's profile Send private message
digimatt
Smarty n00b


Joined: 13 Jan 2005
Posts: 2

PostPosted: Fri May 20, 2005 5:12 am    Post subject: Reply with quote

Well after digging around a little I found a solution that might work. Using:

{capture assign='stuff'}
{my_func param1=this param2=that}
{/capture}

does the trick (sort of). It effectively puts the output of my_func into $stuff. However, it is the literal output, not the returned variable from the function. But what if I wanted to create a function that returned an array, and assign it to a variable from within a template.

I wanted a way to do this without having to mess with PHP at all. I guess it's not possible... or is it?

Any ideas? Thanks.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri May 20, 2005 1:24 pm    Post subject: Reply with quote

Make your function support an assign attribute, you can look at many of them that come with Smarty for an example.

Code:

{my_func param1="this" param2="that" assign="stuff"}

The result is {$stuff}
Back to top
View user's profile Send private message Visit poster's website
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 -> General 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