Passing an array through Liquid

jct_______
New Member
2 0 0

I have a variable, myArray, that I want to simply pass through a Liquid template to be displayed to an end user. Liquid seems to compress all of the array items into a single string. This is what happens:

 

 

# the array
myArray = ["item 1", "item 2"]

# the string I pass to Liquid to be stored as a template and then parsed
"My Array Items: {{myArray}}"

# the final results after I call template.parse
"My Array Items: item1item2"

 

 

  What I want is the following:

 

 

"My Array: ["item1", "item2"]"

 

 

0 Likes
Ninthony
Shopify Partner
1712 241 657

Can you give a little bit better of an example? I'm a little bit confused because it looks like you're writing javascript but you're using liquid. 

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
jct_______
New Member
2 0 0

Sure, sorry. (Very new to Liquid, using it in Ruby). I added quotations where there should have been some to indicate strings.

fwiw, the following is a loose workaround -- basically iterating over the array to create a stringified array.

 

"My Array: [
    {{% for item in myArray %}
       {{tag}},
   {% endfor %}
]"

 

 

0 Likes