Re: [SMARTY] Registering plugins inside a class?
| From: | M Mohr | Date: | Thu, 13 Feb 2003 09:25:38 +0000 |
| Subject: | Re: [SMARTY] Registering plugins inside a class? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7713@lists.php.net to get a copy of this message | ||
On Thu, Feb 13, 2003 at 10:00:26AM +0100, Matthias Mohr wrote:
> Is it possible to register class-functions as plugin-functions?
>
> Here is an example, to understand what I mean:
> --------------------------------------------------------------------------
> class MySmarty extends Smarty {
> function MySmarty {
> parent::Smarty();
> $this->plugins_dir[] = "/myplugins";
> $this->left_delimiter = "<{";
> $this->right_delimiter = "}>";
>
> $this->register_modifier( "test", "smarty_modifier_test" );
> }
>
> function smarty_modifier_test( $sStr ) {
> // do something with the string:
> $sStr = $sStr + "_test";
>
> return( $sStr );
> }
> }
> --------------------------------------------------------------------------
>
> after that I try to use the modifier "test" in my templates.
> But there will be always the error:
> "Smarty error: [in Template.tpl line 23]: [plugin] modifier 'test' is not
> implemented...
>
> I'm using Smarty 2.4.2
> What's wrong? And how can I fix it?
> Or isn't it possible, to use class-functions as plugins?
I'm afraid thats not possible. You have to write a wrapper function:
function smarty_modifier_test( $sStr ) {
return MySmarty::smarty_modifier_test( $sStr );
}
> (BTW, I also tried "MySmarty::smarty_modifier_test" as function-string; same error)
hmm, calls to static methods. i think it would be a nice addition if
smarty supports that. maybe it is easy to add to the compiler-class, but
i'm sure it's not supported by now.
> with regards,
> Matthias
have fun
messju
(BTW: nice fullname! i like it for ages :-)