Get Smarty



Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty



registerFilter() — dynamically register filters


void registerFilter(string type,
                    mixed callback);

Use this to dynamically register filters to operate on a templates. It uses the following parameters:

  • type defines the type of the filter. Valid values are "pre", "post", "output" and "variable".

  • callback defines the PHP callback. it can be either:

    • A string containing the function name

    • An array of the form array($object, $method) with $object being a reference to an object and $method being a string containing the method-name

    • An array of the form array($class, $method) with $class being the class name and $method being a method of the class.

Technical Note

If the chosen function callback is of the form array(&$object, $method), only one instance of the same class and with the same $method can be registered. The latest registered function callback will be used in such a scenario.

A prefilter runs through the template source before it gets compiled. See template prefilters for more information on how to setup a prefiltering function.

A postfilter runs through the template code after it was compiled to PHP. See template postfilters for more information on how to setup a postfiltering function.

A outputfilter operates on a template's output before it is displayed. See template output filters for more information on how to set up an output filter function.

See also unregisterFilter(), loadFilter(), $autoload_filters, template pre filters template post filters template output filters section.

No comments for this page.


Sponsors [info]