Html 调用句柄内的变量

Html 调用句柄内的变量,html,shopify,liquid,Html,Shopify,Liquid,我想用一个变量调用images id,比如 很明显,把手里面没有把手,所以我提出了这个解决方案。我如何清理代码,这样就不必为循环中的每个元素设置if <div class="custom_info__wrapper"> <div class="container"> <div class="row"> {% for i in (1..3) %} {% capture text1 %}custom_info_{{ i }}_text1{

我想用一个变量调用images id,比如

很明显,把手里面没有把手,所以我提出了这个解决方案。我如何清理代码,这样就不必为循环中的每个元素设置if

<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>
我看到你的可翻译字符串有问题,但你会自己解决的