Extending Twig
Extending Twig
Caution
This section describes how to extend Twig as of Twig 1.12. If you are using an older version, read the legacy chapter instead.
Twig can be extended in many ways; you can add extra tags, filters, tests, operators, global variables, and functions. You can even extend the parser itself with node visitors.
Note
The first section of this chapter describes how to extend Twig easily. If you want to reuse your changes in different projects or if you want to share them with others, you should then create an extension as described in the following section.