| Filters | |
| What are filters? | Filters are modules that are used to preprocess .PET files before they are processed by the real template processor. |
| How do filters work? | You have to name the filter(s) you want to use in global.conf (see at <Using a filter>). |
| Using a filter | Filters are chainable, which means multiple filters can be run one after the other. |
| Creating a filter | You can create your own filter easily. |
Filters are modules that are used to preprocess .PET files before they are processed by the real template processor. This allows flexible programming, for example a module could be written that transfers a template to different languages, and is processed after language dependent substitutions take place.
You have to name the filter(s) you want to use in global.conf (see at <Using a filter>). Before the template is processed, these filters are called one after the other (in a pipleline fashion). They can change the content of the templates (pet files), with the result stored on disk (presumably inside the “cache” directory) for the template processor.
This also means that filtering does not take extra runtime : when a .pet file changes, the filters are run once, and the result of the filtering is stored on disk, so there is no further overhead. This makes the use of filters very efficient.
Filters are chainable, which means multiple filters can be run one after the other. You have to list the modules you plan to use as filters in global.conf at “general/template/filters”, e.g. : ... <general> <template> filters = PET::Filter::PreMultiLang PET::Filter::Imaget ... </template> ... </general> ...
Filters are run in the same order as they are listed. Even though in many cases the order is irrelevant, make sure you read the documentation of the filters you plan to use to avoid possible harmful artifacts.
You can create your own filter easily. Use base class PET::Filter, and create a method “process”. At runtime, this method will be passed a pet filename (scalar) and the content of that file (scalarref), respectively. You shall return a scalar with the modified content.
Make sure you design your filter modules so that they can fit anywhere in the filter chain.
See the source of a simple filter for further examples.