Twig / Symfony2 - using a variable inside array merge
symfony, twig
Solution
Enclose the key name in brackets:
{% array1|merge({(var_name1): var_name2}) %}
Problem
``` {% set var_name1 = "hello" %} {% set var_name2 = "there" %} {% array1|merge({var_name1: var_name2}) %} ``` I was hoping the code above would add this to array1: ``` hello:there ``` ...but it adds: ``` var_name1:there ``` I've tried wrapping {{ }} around var_name1. Is it possible to add a record to an array and use a variable for the key?