|
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 |
jazzbazzfazz Smarty n00b
Joined: 08 Oct 2003 Posts: 3
|
Posted: Wed Oct 08, 2003 11:25 pm Post subject: Calling custom functions from inside {if} or {assign} |
|
|
I searched and searched (and tried quite a few things)...
Suppose I want to compare the results of a custom function inside an {if} construction, or assign the result of a function to a new variable...it looks like the way Smarty requires parameters to be listed precludes using functions in such a way.
e.g.
Suppose the function "housevalue" is written to estimate the value of a home, given such parameters as square footage and number of bedrooms
{housevalue sqft=2000 bedrooms=3} might return something like 150000
I use smarty->register_function() to register this function in php/Smarty, then can call it from a Smarty template. Now, what I want to do is use this function in an {if} statement, or in an {assign} statement.
{if housevalue sqft=2000 bedrooms=3 gt 100000} doesn't work...
neither do lots of other wild potshots, e.g.
{if housevalue(2000,3) gt 100000}
...for this latter one I tried using array_values($params), e.g., instead of extract($params).
Any ideas?
Last edited by jazzbazzfazz on Wed May 05, 2010 10:52 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 09, 2003 12:18 am Post subject: |
|
|
This is how other functions assign values:
{housevalue sqft=2000 bedrooms=3 assign="hval"}
Make sure your housevalue function assigns the result, then you can work with {$hval} from there. I'll also point out (as I always do ) that this example of logic should ideally be carried out in the application, not the template.
Monte |
|
Back to top |
|
jazzbazzfazz Smarty n00b
Joined: 08 Oct 2003 Posts: 3
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Oct 09, 2003 4:39 pm Post subject: |
|
|
ahem, you have to actually call
$smarty->assign($params['assign'], $result);
in your plugin-function |
|
Back to top |
|
jazzbazzfazz Smarty n00b
Joined: 08 Oct 2003 Posts: 3
|
|
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
|