How to extend twig¶
If needed twig extensions can be replaced or new extension can be added to the project.
Replacing existing extensions¶
Replacing extension can be done in two ways.
- The first one is to simply add extension to Twig environment.
- The other way is to override extension service of the OXID eShop twig component .
As every extension is a service, so redefining particular service in custom
services.yaml file does the job.
Adding new extension¶
Adding new extension is as simple as defining service. Extension is automatically added to Twig environment if service
services: OxidEsales\Twig\Extensions\StyleExtension: class: OxidEsales\Twig\Extensions\StyleExtension tags: ['twig.extension']
Adding new escapers¶
Every escaper is a class which implements OxidEsalesTwigEscaperEscaperInterface. Escaper is
registered in Twig as service with
services: OxidEsales\Twig\Escaper\MailEscaper: class: OxidEsales\Twig\Escaper\MailEscaper tags: ['twig.escaper']
If needed, escapers can be overloaded by redefining services.