Custom twig function and filter in Drupal 8

Twig is a part of the Symfony framework and introduced as a template engine. Drupal 8 also uses twig as a template engine.

We can modify incoming data to twig using Drupal 8 template hooks but we also need some quick filter and dynamic functions that we can directly inject to a particular template.

Drupal 8 provides a way to create custom twig extension, Let’s how we can do this.