【问题标题】:If no image is uploaded, don't display placeholder image如果没有上传图片,则不显示占位符图片
【发布时间】:2021-10-18 12:21:23
【问题描述】:

如果没有从“设置”面板上传图像,那么我不希望显示默认占位符图像(当前存在的无图像图片。

这里是html代码:

     <div class="Images">
      <div class="image1">
      <img src="{{section.settings.image1 | img_url: '120x120'}}"/>
      </div>
        <div class="image2">
      <img src="{{section.settings.image2 | img_url: '120x120'}}"/>
      </div>
        <div class="image3">
      <img src="{{section.settings.image3 | img_url: '120x120'}}"/>
      </div>
        <div class="image4">
      <img src="{{section.settings.image4 | img_url: '120x120'}}"/>
      </div>
        <div class="image5">
      <img src="{{section.settings.image5 | img_url: '120x120'}}"/>
      </div>
        <div class="image6">
      <img src="{{section.settings.image6 | img_url: '120x120'}}"/>
      </div>   
     </div>

架构代码:


  {
              "type":"image_picker",
              "label":"image 1",
              "id":"image1"
              },
              {
              "type":"image_picker",
              "label":"image 2",
              "id":"image2"
              },
              {
              "type":"image_picker",
              "label":"image 3",
              "id":"image3"
              },
              {
              "type":"image_picker",
              "label":"image 4",
              "id":"image4"
              },
              {
              "type":"image_picker",
              "label":"image 5",
              "id":"image5"
              },
              {
              "type":"image_picker",
              "label":"image 6",
              "id":"image6"
              },

如何让它工作,如果没有上传图片,那么就不应该有占位符?

【问题讨论】:

  • 只需将代码包装到 if 条件中并检查是否添加了图像然后添加 img 标签,否则不添加。 ` {% if section.settings.image1 != blank %}img 标签放在这里{% endif %}`
  • 谢谢 - 工作。有没有更好的方法让我编写代码,例如如果只有 2 个图像,那么 2 个图像是中心的?目前,如果有 2 张图片,则其他 4 张图片有一个空白区域(如果有意义的话),这会使布局看起来很奇怪。

标签: html shopify


【解决方案1】:

就这么简单:

{% if section.settings.image1 %}
    <div class="image1">
        <img src="{{section.settings.image1 | img_url: '120x120'}}"/>
    </div>
{% endif %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 2020-12-05
    相关资源
    最近更新 更多