jmf/twig-array

Twig extension for interacting with arrays in Twig templates.

1.0.0 2024-06-05 02:59 UTC

This package is auto-updated.

Last update: 2024-09-05 03:30:33 UTC


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() %}