Skip to content

Conversation

@mylesthedev
Copy link

It might pay to leave it up to the twig being passed through to have the square brackets.
It's much more difficult to remove [] in twig than it is to add them e.g. json_encode.

For example:

    {% set myArray = [] %}
    {% for item in items %}
        {% set myArray = myArray|merge([{
            'label': item.label,
            'value': item.id
        }]) %}
    {% endfor %}
    {{ myArray | json_encode() | raw }}

This should be left up to the twig code as it's much easier to add square brackets like this in twig than it is to remove them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant