Twig extension is about custom type defined about Twig template PHP engine. About Common additional features for Twig that do not directly belong in core
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.
As a rule of thumb, use functions for frequently used features and global objects for everything else.
Keep in mind the following type available when you want to extend Twig:
- global: Helper object
- function: Content generation
- filter: Value transformation
- tag: DSL language construct
- test: Boolean decision
- operator: Values transformation
Detailed documentation about extending twig is available here