Павел Бражко Павел Бражко - 1 year ago 342
Twig Question

TWIG, dynamic associative array key

I need to create a array with a dynamic key.


{% set key = 'a' %}
{% set value = 'b' %}
{% set array = {key:value} %}

Answer Source

I find a workaround for this problem: if you surround the key with parenthesis the key of array take the value of the variable instead of the name. So try simple this:

{% set array = { (key): value} %}

Here a working solutions

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download