【问题标题】:Shopify (Liquid): Syntax error expected close_square but found commaShopify(液体):语法错误应为 close_square,但发现逗号
【发布时间】:2018-11-20 19:39:13
【问题描述】:

我正在 Shopify (Liquid) 中创建一个数组,但出现错误,

            {% assign numbers = [   
                                    "One", 
                                    "TWo", 
                                    "three",
                                    "bla"                                   
                                 ] 
            %}

第 126 行 — Liquid 语法错误:应为 close_square 但找到逗号 在 "{{[ "一","Two", "三","bla" ] }}"

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    没有办法在液体中创建这样的数组。

    相反,您可以使用split 过滤器从字符串创建数组。

    {% assign numbers = "one,two,three,four" | split: "," %}
    <pre>{{ numbers | inspect }}</pre>
    

    您还可以创建一个空数组并使用 push 过滤器提供它

    {% comment %} +++ Creates an empty array +++ {% endcomment %}
    {% assign numbers = "" | split: "" %}
    <pre>{{ numbers | inspect }}</pre>
    {% comment %} +++ Feed the beast +++ {% endcomment %}
    {% assign numbers = numbers | push: "one" %}
    <pre>{{ numbers | inspect }}</pre>
    {% assign numbers = numbers | push: "two" %}
    <pre>{{ numbers | inspect }}</pre>
    

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 1970-01-01
      • 2017-12-01
      • 2012-06-06
      • 1970-01-01
      相关资源
      最近更新 更多