Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: Expected close_square but found pipe

Solved

Expected close_square but found pipe

yewy89
Shopify Partner
2 0 0

I try to custom the tex with image block and write a for loop below. But it can't be saved due to the error: Liquid syntax error (line 195): Expected close_square but found pipe in "{{block.settings["image_" | append: i] }}"

 

{% for i in (1..5) %}
{%- assign image = block.settings["image_" | append: i] -%}
{%- assign image_position = block.settings["image_position_" | append: i] -%}
{%- assign content = block.settings["content_" | append: i] -%}

{%- if image != blank -%}
 <div> xxxxxxxx  </div>
{%- endif -%}
{% endfor %}

 

Can anybody please help on this issue? Thanks

Accepted Solution (1)

Cherb20
Shopify Partner
6 2 4

This is an accepted solution.

Rather than trying to append the index of the for loop within the square braces, I would seperate them out first by assigning an index variable by itself, then using that variable within your square braces. 

 

{% for i in (1..5) %}

  {%- assign image_key = "image_" | append: i -%}

  {%- assign image_position_key = "image_position_" | append: i -%}

  {%- assign content_key = "content_" | append: i -%}

 

  {%- assign image = block.settings[image_key] -%}

  {%- assign image_position = block.settings[image_position_key] -%}

  {%- assign content = block.settings[content_key] -%}

  {%- if image != blank -%}

   <div> xxxxxxxx </div>

  {%- endif -%} 

{% endfor %}

 

It looks like a syntax error and you're trying to assign the key within the square braces which isn't allowed in Liquid. 

 

Hope this helps. If it works, please accept the solution 🙂

If I answered your question, please Accept my answer as the solution 🙂
If you found any information I've provided helpful, please give a Thumbs Up

If you have any questions, feel free to reach out or message me.

View solution in original post

Reply 1 (1)

Cherb20
Shopify Partner
6 2 4

This is an accepted solution.

Rather than trying to append the index of the for loop within the square braces, I would seperate them out first by assigning an index variable by itself, then using that variable within your square braces. 

 

{% for i in (1..5) %}

  {%- assign image_key = "image_" | append: i -%}

  {%- assign image_position_key = "image_position_" | append: i -%}

  {%- assign content_key = "content_" | append: i -%}

 

  {%- assign image = block.settings[image_key] -%}

  {%- assign image_position = block.settings[image_position_key] -%}

  {%- assign content = block.settings[content_key] -%}

  {%- if image != blank -%}

   <div> xxxxxxxx </div>

  {%- endif -%} 

{% endfor %}

 

It looks like a syntax error and you're trying to assign the key within the square braces which isn't allowed in Liquid. 

 

Hope this helps. If it works, please accept the solution 🙂

If I answered your question, please Accept my answer as the solution 🙂
If you found any information I've provided helpful, please give a Thumbs Up

If you have any questions, feel free to reach out or message me.