使用循环索引动态输出液体对象
Dynamically outputting liquid object using loop index
我一直在尝试使用变量迭代一个部分的输出,但我找不到通过连接索引来动态输出液体对象的方法。 images[i]
是我在 {% schema %}
部分设置的图像的id。
{% for i in (1 .. 5) %}
{% if section.settings.images[i] != blank %}
{{ section.settings.image[i] }}
{% endif %}
{% endfor %}
你快到了。
您需要分配 handle/id,因为目前 images[i]
指向一个不正确的图像数组。
代码应该是这样的:
{% for i in (1 .. 5) %}
{% assign image_handle = 'images' | append: i %}
{% if section.settings[image_handle] != blank %}
{{ section.settings[image_handle] }}
{% endif %}
{% endfor %}
假设您的图片 ID 名为 images1
、images2
、images3
等。
PS:
我不确定你的完整代码,但如果你有一个部分并且你没有使用它的块,为什么不使用它们而不是预定义的部分字段?
{%- for block in section.blocks -%}
{%- if block.settings.image != blank -%}
{{ block.settings.image | img_url: '600x' | img_tag }}
{%- endif -%}
{%- endfor -%}
{% schema %}
{
"name": "Images",
"max_blocks": 5,
"blocks": [
{
"type": "image",
"name": "Image",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
}
]
}
]
}
{% endschema %}
我想要这个代码,非常感谢...
这是我的示例代码。
{% for i in (1..10) %}
{% assign display_brand = 'display_brand_' | append: i %}
{% assign image_handle = 'image_' | append: i %}
{% assign link_handle = 'link_' | append: i %}
{% if block.settings[display_brand] %}
<div class="brand-item">
<div class="brand-top">
{% if block.settings[image_handle] != blank %}
<img src="{{ block.settings[image_handle] | img_url: '350x' }}" alt="" />
{% else %}
<div class="not_img">
350 x 375px
</div>
{% endif %}
</div>
<a href="{{block.settings[link_handle]}}" class="btn">{% render 'multilang' with block.settings.itembuttontext %}</a>
</div>
{% endif %}
{% endfor %}
我一直在尝试使用变量迭代一个部分的输出,但我找不到通过连接索引来动态输出液体对象的方法。 images[i]
是我在 {% schema %}
部分设置的图像的id。
{% for i in (1 .. 5) %}
{% if section.settings.images[i] != blank %}
{{ section.settings.image[i] }}
{% endif %}
{% endfor %}
你快到了。
您需要分配 handle/id,因为目前 images[i]
指向一个不正确的图像数组。
代码应该是这样的:
{% for i in (1 .. 5) %}
{% assign image_handle = 'images' | append: i %}
{% if section.settings[image_handle] != blank %}
{{ section.settings[image_handle] }}
{% endif %}
{% endfor %}
假设您的图片 ID 名为 images1
、images2
、images3
等。
PS:
我不确定你的完整代码,但如果你有一个部分并且你没有使用它的块,为什么不使用它们而不是预定义的部分字段?
{%- for block in section.blocks -%}
{%- if block.settings.image != blank -%}
{{ block.settings.image | img_url: '600x' | img_tag }}
{%- endif -%}
{%- endfor -%}
{% schema %}
{
"name": "Images",
"max_blocks": 5,
"blocks": [
{
"type": "image",
"name": "Image",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
}
]
}
]
}
{% endschema %}
我想要这个代码,非常感谢...
这是我的示例代码。
{% for i in (1..10) %}
{% assign display_brand = 'display_brand_' | append: i %}
{% assign image_handle = 'image_' | append: i %}
{% assign link_handle = 'link_' | append: i %}
{% if block.settings[display_brand] %}
<div class="brand-item">
<div class="brand-top">
{% if block.settings[image_handle] != blank %}
<img src="{{ block.settings[image_handle] | img_url: '350x' }}" alt="" />
{% else %}
<div class="not_img">
350 x 375px
</div>
{% endif %}
</div>
<a href="{{block.settings[link_handle]}}" class="btn">{% render 'multilang' with block.settings.itembuttontext %}</a>
</div>
{% endif %}
{% endfor %}