A space to discuss online store customization, theme development, and Liquid templating.
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
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
Solved! Go to the solution
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 🙂
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 🙂