Re: [SMARTY-DEV] Modifier function arguments
[email protected] (boots)
| Newsgroups | php.smarty.dev |
|---|---|
| Message-ID | <[email protected]> |
--- Johannes Findeisen <[email protected]> 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