Part of the Twig ecosystem · 43 projects
This module provides a plugin system for Drupal to add custom Twig filters and functions. It allows developers to easily extend Twig's capabilities within their Drupal projects.
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() %}
Ask your assistant about Twig Extender
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Twig ecosystem
Most installed first