Re: [SMARTY-DEV] Modifier function arguments
| From: | boots | Date: | Tue, 15 Feb 2005 04:50:54 +0000 |
| Subject: | Re: [SMARTY-DEV] Modifier function arguments | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2643@lists.php.net to get a copy of this message | ||
--- Johannes Findeisen <mailman@hanez.org> wrote:
> Hello all,
Hi
> i'm writing a small website management with the use of smarty. Now
> i'm at a
> poit where i need the $smarty object in the modifier function. Is
> there a way
> to give the modifier function more then one argument?
Do you mean {$foo|bar:p1:p2} ? You need to pass as many parameters to
your modifier as you have non-default parameters in your modifier's
function signature. Parameters are passed to the modifier function in
the order they are given in the template.
> There ist on $message available in the function. In the outputfilters
> is the parameter i need in the modifiers: &$smarty.
>
> I really need help because i'm writing a modifier which shoul have
> access to all assigned variables. In an outputfilter i have written
> i'm using these vars like this: $smarty->_tpl_vars['VAR_NAME']
One thing to do is to implement your modifier as a method of your
(extended) Smarty class. Then manually register the modifier in the
constructor. That way the modifier has access to the current instance
of Smarty using $this.
Trivial Example:
class MySmarty extends Smarty {
function MySmarty()
{
$this->Smarty();
$this->register_modifier('getvar', array('MySmarty',
'modifier_getvar'));
}
function modifier_getvar($bar, $baz=null)
{
return $this->_tpl_vars($bar);
}
}
----
{assign var=test value=bar}
{"test"|getvar} {* results in 'bar' *}
xo boots
> Kind regards
>
> Johannes