Skip to content

JakeFr/TwigSet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JakeFR / TwigSet

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 #}

About

Set tag for twig with support of combined operators

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages