|
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 |
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Wed Sep 17, 2003 1:33 pm Post subject: Q about plugins and functions |
|
|
Hey y'all
I'm writing my own modifier, let's call it foo.
So, somewhere I register that modifier (of course before displaying, and assume that $this is a Smarty object):
Quote: | $this->register_modifier( 'foo', 'func_foo' ); |
In my template I have something like this:
Quote: | <{$item->bar|upper|foo}> |
And, in my SMARTY_DIR/plugins, I have a file called modifier.func_foo.php:
Quote: | function func_foo( $params, $content, &$smarty, &$repeat ) {
echo "f_called";
} |
However, I keep on getting this error:
Quote: | Fatal error: Smarty error: [in test.tpl line x]: [plugin] modifier 'foo'is not implemented (smarty.class.php, line 2462) in /usr/some/dir on line 2652 |
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Sep 17, 2003 1:58 pm Post subject: |
|
|
you'r mixing two ways here:
you can a) register the modifier explicitely:
function func_foo() { ... }
$this->register('foo', 'func_foo');
[note the function has to be declared or included by yourself]
or you can b) autoload the modifier:
no register-call at all, simply put modifer.[name].php in plugins dir.
the function in it *has to* be named smarty_modifier_[name] then.
but you can not declare it explicitely and make smarty it autoload then.
HTH
messju |
|
Back to top |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Wed Sep 17, 2003 2:41 pm Post subject: |
|
|
First, thanks for the swift reply.
Mm'kay, pre/post/outputfilters have to be explicitly loaded, but modifiers not. Okay, got that.
Got it working though, by auto-loading the file modifier.foo.php, with a function called smarty_modifier_foo in it.
Thanks! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Sep 17, 2003 2:46 pm Post subject: |
|
|
modifiers are loaded as soon as they are used in a template.
filters can be announced in $smarty->auto_load_filters and then are loaded on demand. |
|
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
|