Pre-, post-, and output filters
| From: | Andrei Zmievski | Date: | Mon, 15 Apr 2002 21:57:17 +0000 |
| Subject: | Pre-, post-, and output filters | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-3758@lists.php.net to get a copy of this message | ||
I don't really like the way the pre/postfilters currently work,
especially now that we are talking about adding output filters. Let me
explain why.
So far it's been the convention that prefilters and postfilters are
automatically loaded and executed for every compiled template. If you
didn't want them to operate on a specific template, you had to
unregister them right before calling display() or fetch(). To me, that
seems backwards -- indicating that you don't want something done,
instead of what you do want done. Originally we just wanted people to be
able to drop plugins into the plugins directory and have them work, and
it seems to be working fine for everything except prefilters and
postfilters, because they are not adhering to the philosophy that a
plugin is loaded automatically when it's used.
With output filters, this egregious behavior is exposed even more.
Suppose you have three output plugins: one that trims whitespace, one
that removes HTML comments, and one that somehow transforms the output
to be XHTML compliant. If you only want to use whitespace-trimming
plugin, you have to unregister the other two, either in an extension
class or right before calling display().
I think we should change behavior for pre, post, and output filters to
be as follows.
The filters will not be loaded automatically.
There will be new API function:
function load_filter($type, $name = null);
$type can be 'pre', 'post', and 'output'. If the name is omitted, then
all the filters of that type are loaded. Otherwise, only the specified
one is loaded.
Additionally, there would be an $autoload_filters variable in Smarty,
that could be used to tell Smarty to always load your favorite filters.
It would be structured like this, for example:
$smarty->autoload_filters = array('pre' => array('stamp',
'mark'),
'output' => 'trimwhitespace');
We could also make so there is instead a generic load_plugin() function
and $autoload_plugins variable, but since all other kinds of plugins are
autoloaded on-demand already, it might not be too useful.
Thoughts?
-Andrei
"Remember, high-tech means breaks down next week, while cutting edge means
breaks down this afternoon." -- Bruce Sterling