jake-fr / twig-set
Set tag for twig with support of combined operators
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jake-fr/twig-set
Requires
- twig/twig: ^2.0
This package is not auto-updated.
Last update: 2025-10-20 21:03:09 UTC
README
set tag for twig 2 with support of combined operators.
Requirements
This librairy requires Twig 2 and PHP 7
Installation
Install via Composer
$ composer require jake-fr/twig-set
Add the extension to twig
The constructor expects one parameter:
An array of supported binary nodes with symbol as key and the binary node class name as value.
$operators = [ '+' => 'Twig_Node_Expression_Binary_Add', '-' => 'Twig_Node_Expression_Binary_Sub', '~' => 'Twig_Node_Expression_Binary_Concat', '*' => 'Twig_Node_Expression_Binary_Mul', '/' => 'Twig_Node_Expression_Binary_Div', '//' => 'Twig_Node_Expression_Binary_FloorDiv', '%' => 'Twig_Node_Expression_Binary_Mod', '**' => 'Twig_Node_Expression_Binary_Power', ]; $twig->addExtension(new \JakeFr\TwigSet\Extension($operators));
Usage
{% set foo = 4 %} {{ foo }} {# will ouput 4 #} {% set foo += 3 %} {{ foo }} {# will ouput 7 #}