How to set associative array in volt?

I want to set associative array in volt

{% set tempKey = "Name" %}

{% set tempArray[tempKey] = "Mike" %}

how to do that?


{% set array = ['key': value] %}


Hi, But if the Key is another variable, it's not working

{% set array = ['key': value] %}


Yeah, you're right, 'cause you can't put a variable like a key. key is a string value, not a variable.


@sunz5010 if you are doing something complicated then you should push that logic into the controller and then add that data to the View with View::setVar. If you want to be able to reuse the logic then you can put all of that logic into an object and then add this to the view in the same way. Volt is not suitable for complex mapping.