Add a simple plugin system to add new twig extensions (Filter and Functions). Provides a new service provider for "twig.extensions" to add new plugins.
Versions
Drupal 8.2 or lower: Use Twig Extender 8.1
Drupal 8.3 or higher: Use Twig Extender 8.2
Documentation
Basic filter and functions: https://github.com/erik-seifert/twig_extender
Extra filter and function: https://github.com/erik-seifert/twig_extender/tree/8.x-2.x/modules/twig_...
Add new functions and filters
Please add your suggestions here.
https://www.drupal.org/node/2701695
Simple Plugin
<?php
namespace Drupal\twig_extender\Plugin\TwigPlugin;
use Drupal\twig_extender\Plugin\Twig\TwigPluginBase;
use Drupal\Component\Utility\Unicode;
/**
* Example plugin Hello World.
*
* @TwigPlugin(
* id = "twig_extender_hello",
* label = @Translation("Hello world plugin"),
* type = "function",
* name = "hello",
* function = "hello"
* )
*/
class HelloWorld extends TwigPluginBase {
/**
* Implement hello world function.
*/
public function hello() {
return 'Hello World';
}
}
Using in Template
{% hello() %}
Supporting organizations:
Development
Development
Project information
- Project categories: Content editing experience, Developer tools
545 sites report using this module
- Created by erik seifert on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.

