jmf / twig-array
Twig extension for interacting with arrays in Twig templates.
1.0.0
2024-06-05 02:59 UTC
Requires
- php: >=8.3
- twig/twig: ^3.0
Requires (Dev)
- phing/phing: ^2.17
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
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() %}