|
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 |
inaki Smarty n00b
Joined: 28 Aug 2006 Posts: 1
|
Posted: Mon Aug 28, 2006 11:18 am Post subject: Access template variables from a modifier |
|
|
Hi, I'm writing a very simple modifier to change a number for an image with a number of stars (for example, change the value 3.2 for an img with 3 stars).
My problem is that I need access from the modifier to a template variable called $url, and I don't know how to do it.
In PHP I do:
$smarty->assign( "rating", $rating );
$smarty->assign( "url", "http://www.mydomain.com/" );
And then in the template I want to be able to do:
{$rating|stars} ({$rating})
For that I am writint the "stars" modifier:
Code: |
function smarty_modifier_stars( $string )
{
$val = round($string);
$val = max( 0, min( 5, $val ) ); // between 0 and 5
return '<img src="'.SMARTY_VAR_URL.'images/stars_'.$val.'.jpg" alt="'.$val.' stars" />';
}
|
How can I access the $url variable from the modifier? I'm sure it's something stupid, but I've been looking around and haven't been able to find the solution.
One solution would be to pass $url as an argument to the modifier, but I'm sure there's something more elegant.
Thanks! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Aug 28, 2006 12:25 pm Post subject: Re: Access template variables from a modifier |
|
|
inaki wrote: | One solution would be to pass $url as an argument to the modifier, but I'm sure there's something more elegant. |
I doubt. |
|
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
|