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?



20.4k

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


1.5k

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


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


20.4k

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



48.3k

@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.