Re: Modifier function arguments

boots <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
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

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.