There are three main ways to create filters and make them available on Smarty templates:
register_*filter
functions.load_filter
function.autoload_filters
Smarty property to make it load the appropriate filters automatically for you.Let’s go over these different ways now. To register a filter plug-in at run time, you need to use one of the following Smarty functions:
Type |
Method signature to register a plug-in |
---|---|
Prefilters |
|
Postfilters |
|
Output filters |
|
Please note that the parameter called impl
above refers to the function or method name that Smarty will call, and it can be one of the following:
array($object, ‘method_name’)
array(‘class_name’, ‘method_name’)
When actually writing the PHP code for the filter plug-ins, follow these rules for the function arguments:
Type |
Function signature when writing the filter |
---|---|
Prefilters |
|
Postfilters |
|
Output filters |
|
What this means is that for filter plug-ins, Smarty will pass the template source or template output as the first argument and the special Smarty object as the second argument to your PHP function, and expect you to return the modified source or output from that function.
18.220.136.165