1

I can't wrap my head around this. I'm on mobile so forgive me. I'm trying to add dynamic values to an array like this:

{%  set myArray = myArray|merge("href": {{ product.href }})%}.

I'm getting the 'A hash key must be a quotes string, a number, a name...'.

What am I doing wrong?

1 Answer 1

1

You have syntax error .

It is wrong

{%  set myArray = myArray|merge("href": {{ product.href }})%}.

Use this code instead

   {%  set myArray = myArray|merge({ 'href': product.href } ) %}.

The merge filter works on hashes. For hashes, the merging process occurs on the keys: if the key does not already exist, it is added but if the key already exists, its value is overridden.

Sign up to request clarification or add additional context in comments.

1 Comment

While this may answer the question, it's better to explain what needs to be changed than just dropping a line of code without further explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.