-1

I want to put Liquid code in a metafield with value type string. This is the Liquid code:

{% 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 %}

The Liquid code works fine when I try it on shopify. The problem here is this error on the 1st row:

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

Any suggestions? It looks like this:

$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"
    )
);
D Malan
  • 10,272
  • 3
  • 25
  • 50
someoneuseless
  • 303
  • 3
  • 17

1 Answers1

0

Change from double to single quotes in <div class="slider"> and <img src="{{ field | last }}" />

changing it to -> <div class='slider'> and <img src='{{ field | last }}' />