|
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 |
digimatt Smarty n00b
Joined: 13 Jan 2005 Posts: 2
|
Posted: Fri May 20, 2005 3:52 am Post subject: Assigning function output to variable. |
|
|
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 |
|
digimatt Smarty n00b
Joined: 13 Jan 2005 Posts: 2
|
Posted: Fri May 20, 2005 5:12 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri May 20, 2005 1:24 pm Post subject: |
|
|
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 |
|
|
|
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
|