jmf / twig-array
Twig extension for interacting with arrays in Twig templates.
1.0.1
2026-05-30 20:00 UTC
Requires
- php: ^8.3
- twig/twig: ^3.0
Requires (Dev)
- overtrue/phplint: ^9
- phpstan/phpstan: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^12|^13
- rector/rector: ^2
- squizlabs/php_codesniffer: ^4
README
Installation & Requirements
Install with Composer:
composer require jmf/twig-array
Usage in Twig templates
array_set()
Sets a specific key in an array.
{% set values = {} %}
{% set values = values|array_set('foo', 'bar') %}
array_unset()
Unsets a specific key in an array.
{% set values = {'foo': 'bar'} %}
{% set values = values|array_unset('foo') %}
array_push()
Appends a new value at the end of an array.
{% set values = {'foo'} %}
{% set values = values|array_push('bar') %}
array_pop()
Removes the last item of an array.
{% set values = {'foo', 'bar'} %}
{% set values = values|array_pop() %}
array_unshift()
Appends a new value at the beginning of an array.
{% set values = {'foo'} %}
{% set values = values|array_unshift('bar') %}
array_shift()
Removes the first item of an array.
{% set values = {'foo', 'bar'} %}
{% set values = values|array_shift() %}