Edit on GitHub
Jump to docs navigation

Twig Components / Methods / map

Note: You are currently reading the documentation for Bolt 5.0. Looking for the documentation for Bolt 5.2 instead?

map(arrow) is a Twig filter to apply an arrow function to the elements of a sequence or a mapping. The arrow function receives the value of the sequence or mapping:

{% set people = [
    {first: "Bob", last: "Smith"},
    {first: "Alice", last: "Dupond"},
] %}

{{ people|map(p => "#{p.first} #{p.last}")|join(', ') }}
{# outputs Bob Smith, Alice Dupond #}

The arrow function also receives the key as a second argument:

{% set people = {
    "Bob": "Smith",
    "Alice": "Dupond",
} %}

{{ people|map((last, first) => "#{first} #{last}")|join(', ') }}
{# outputs Bob Smith, Alice Dupond #}

Note that the arrow function has access to the current context.

ArgumentsΒΆ

  • arrow: The arrow function

Source: Twig



Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.