Skip to content
Advertisement

key value being replaced by ‘key’ when using merge() in twig

I am trying to add pairs of key value to an array with their current values for all those attributes not starting by ‘_’. For some reason, the merge replaces the value of “key” (i.e slug) with the string ‘key’.

For example when slug is the only attribute with key not starting with ‘_’,

JavaScript

it behaves as follows:

JavaScript

I have added what the dumps return next to them.

The final dump returns

JavaScript

while i’m expecting

JavaScript

I’d say it’s a similar problem to Twig forgets array-keys but the conclusion on that question is that is a mongodb problem and I am not using it. I am working with attributes from the request.

For some reason, the merge({ key : value}) is behaving as merge({ ‘key’ : value}).

Advertisement

Answer

You need to wrap your variable with parenthesis to be able to use it as a key.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement