![](/img/trans.png)
[英]Shopify / Liquid - adding new contact form textarea/variable to be captured
[英]Calling variable inside handle Shopify Liquid
我想用像这样的变量来调用图像id
<img src="{{ settings.custom_info_{{ i }}}_img1 | img_url: 'master' }}">
显然,手柄内部没有任何手柄,因此我提出了这种解决方案。 我该如何清理我的代码,这样就不必对循环中的每个元素都进行查询了?
<div class="custom_info__wrapper">
<div class="container">
<div class="row">
{% for i in (1..3) %}
{% capture text1 %}custom_info_{{ i }}_text1{% endcapture %}
{% capture text1_lang %}custom_blocks.custom_info_block_{{ i }}.text_1{% endcapture %}
{% capture text2 %}custom_info_{{ i }}_text2{% endcapture %}
{% capture text2_lang %}custom_blocks.custom_info_block_{{ i }}.text_2{% endcapture %}
{% capture img1 %}custom_info_{{i}}_img1{% endcapture %}
<div class="col-sm-4 custom_info custom_info__{{ i }}">
{% assign A = text1_lang | t %}{% if A.size > 0 %}<h6 class="heading_border-old">{{ A }}</h6>{% else %}<h6 class="heading_border-old">{{ settings[text1] }}</h6>{% endif %}
{% if i == 1 %}
<img src="{{ settings.custom_info_1_img1 | img_url: 'master' }}" />
{% elsif i == 2 %}
<img src="{{ settings.custom_info_2_img1 | img_url: 'master' }}" />
{% elsif i ==3 %}
<img src="{{ settings.custom_info_3_img1 | img_url: 'master' }}" />
{% endif %}
{% assign B = text2_lang | t %}{% if B.size > 0 %}<p>{{ B }}</p>{% else %}<p>{{ settings[text2] }}</p>{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
在这里,您可以看到代码的更干净版本。
<div class="custom_info__wrapper">
<div class="container">
<div class="row">
{% for i in (1..3) %}
{% capture text %}custom_info_{{ i }}_text{{ i }}{% endcapture %}
{% capture text_lang %}custom_blocks.custom_info_block_{{ i }}.text_{{ i }}{% endcapture %}
{% capture img %}custom_info_{{i}}_img{{ i }}{% endcapture %}
<div class="col-sm-4 custom_info custom_info__{{ i }}">
{% if forloop.index == 1 %}
{% assign A = text_lang | t %}{% if A.size > 0 %}<h6 class="heading_border-old">{{ A }}</h6>{% else %}<h6 class="heading_border-old">{{ settings[text] }}</h6>{% endif %}
{% endif %}
<img src="{{ settings[img] | img_url: 'master' }}" />
{% if forloop.index == 2 %}
{% assign B = text_lang | t %}{% if B.size > 0 %}<p>{{ B }}</p>{% else %}<p>{{ settings[text] }}</p>{% endif %}
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
我发现您的可翻译字符串存在问题,但您可以自己解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.