【问题标题】:Liquid - if field contains content then display this html, else if empty then display nothingLiquid - 如果字段包含内容则显示此 html,否则如果为空则不显示
【发布时间】:2016-05-20 02:54:53
【问题描述】:

我有一个 LI 列表,其中包含从我的 CMS 自动提取的每个 LI 中的图像(我的 cms 具有包含 img src 的字段)。 有 10 幅图像(10 里)。我需要使用 Liquid,以便如果该字段不包含任何 img src 则显示 NOTHING。否则,如果它确实包含内容,则显示 html。例如

{% if imagefield1 == imgsrc (e.g. /images/steve.jpg) %}
<li><img src="imagefield1"></li>
{% else %}
{% endif -%}

{% if imagefield2 == imgsrc %}
<li><img src="imagefield2"></li>
{% else %}
{% endif -%}

等等

谁能帮我构造我的液体 if 语句?

【问题讨论】:

    标签: if-statement conditional-statements liquid


    【解决方案1】:
    {% for i in (1..10) %}
        {% capture img_src %}imagefield{{ i }}{% endcapture %}
        {% if img_src == imgsrc %}
        <li>
          <img src="{{ img_src}}">
        </li>
        {% endif %}
    {% endfor%}
    

    【讨论】:

    • 请定义imgsrc的值
    猜你喜欢
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多