如何将液态代码放在php字符串中

时间:2019-07-08 10:36:31

标签: php codeigniter liquid shopify-app

我想将Liquid代码放在具有值类型字符串的元字段中。这是液体代码:

{% unless shop.metafields.cmld == blank %}
{%- assign cmld = shop.metafields.cmld -%}
 <div class="slider">
   {%- for field in cmld -%}
        <div>
            <img src="{{ field | last }}" />
        </div>
    {% endfor %}
</div>
{% endunless %}

当我在shopify上尝试使用Liquid代码时,它工作正常。 这里的问题是第一行的错误:

{%'(T_CONSTANT_ENCAPSED_STRING), expecting ')' in .....

有什么建议吗?看起来像这样:

$add_metafield= array(
    "metafield" => array(
        "namespace"=> $metafield_namespace,
        "key"=> "something",
        "value" => "{% unless shop.metafields.".$metafield_namespace." == blank %}{%- assign ".$metafield_namespace." = shop.metafields.".$metafield_namespace." -%}<div class="slider">{%- for field in ".$metafield_namespace." -%}<div><img src="{{ field | last }}" /></div>{% endfor %}</div>{% endunless %}",
        "value_type" => "string"
    )
);

1 个答案:

答案 0 :(得分:0)

<div class="slider"><img src="{{ field | last }}" />中的双引号改为单引号

将其更改为-> <div class='slider'><img src='{{ field | last }}' />