【问题标题】:Shopify select SVG in section blockShopify 在部分块中选择 SVG
【发布时间】:2018-07-30 18:29:47
【问题描述】:

我正在尝试构建一个块,允许商家在我上传到主题的 sn-ps 文件夹的多个 SVG 之间进行选择。

这里的代码对我来说很有意义,但 Shopify 不会输出任何 SVG。它默认为“未选择 SVG”。

这里是for循环:

  {% for block in section.blocks %}
    <div class="grid__item large--one-third text-center reason-block">
      {% case svg__choice %}
        {% when block.settings.svg == 'family' %}
          {% include 'svg--family' %}
        {% when block.settings.svg == 'bottles' %}
          {% include 'svg--plastic' %}
        {% when block.settings.svg == "globe" %}
          {% include 'svg--globe' %}
        {% else %}
          No SVG Selected
      {% endcase %}
      <h4 class="h4v3">{{ block.settings.title }}</h4>
      <p>{{ block.settings.text }}</p>
    </div>
  {% endfor %}

这是我的 {% schema %}:

"blocks": [
      {
        "type": "select",
        "name": "Standard Block",
        "settings": [
          {
            "type": "select",
            "id": "svg",
            "label": "Select SVG code",
            "options": [
              {
                "value": "family",
                "label": "Family"
              },
              {
                "value": "globe",
                "label": "Globe"
              },
              {
                "value": "bottles",
                "label": "Bottles"
              }
            ],
            "default": "family"
          },
          {
            "type": "text",
            "id": "title",
            "label": "Block Title"
          },
          {
            "type": "textarea",
            "id": "text",
            "label": "Block Paragraph"
          }
        ]
      }
    ]

感谢任何帮助!

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    找到了答案。不得不使用 if/else 而不是 case。答案应该是这样的:

      {% for block in section.blocks %}
        <div class="grid__item large--one-third text-center reason-block">
    
            {% if block.settings.svg == 'family' %}
              {% include 'svg--family' %}
            {% elsif block.settings.svg == 'bottles' %}
              {% include 'svg--plastic' %}
            {% elsif block.settings.svg == 'globe' %}
              {% include 'svg--globe' %}
            {% else %}
              No SVG Selected
            {% endif %}
    
          <h4 class="h4v3">{{ block.settings.title }}</h4>
          <p>{{ block.settings.text }}</p>
        </div>
      {% endfor %}
    

    【讨论】:

      【解决方案2】:

      您的case/when syntax 不正确。

      必须阅读:

        {% case block.settings.svg %}
          {% when 'family' %}
            {% include 'svg--family' %}
          {% when 'bottles' %}
            {% include 'svg--plastic' %}
          {% when "globe" %}
            {% include 'svg--globe' %}
          {% else %}
            No SVG Selected
        {% endcase %}
      

      【讨论】:

      • 感谢您的解决方案。如果需要再次出现,我会试一试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 2020-07-20
      • 2013-06-20
      • 1970-01-01
      相关资源
      最近更新 更多