skip to Main Content

In my shopify store, I am using SuperFields in order to customize my site, though my question isn’t about the app. On one of my pages, I need the value for the following:

variant.metafields.sf_{{ collection.title | downcase }}[meta_tag_key]

The value should be 0 or 1. If I evaluate the statement directly, such as:

{if variant.metafields.sf_{{ collection.title | downcase }}[meta_tag_key] =1%}

It throws an error when I render the page: Unexpected character ‘{‘

I’ve also tried the following:

{% capture defaultImage %}variant.metafields.sf_{{ collection.title | downcase }}[meta_tag_key]{% endcapture %}
{% assign test = defaultImage %}

But ‘test’ is considered nil and doesn’t return any value. I have tried to search for answers here and on the shopify forum, but, as my clumsy post title suggests, I’m having a hard time concisely searching for a solution to this problem. Any help is greatly appreciated.

3

Answers


  1. You are missing a % sign in your code. Hence the error message. Your if statement started with {% and not just {

    Login or Signup to reply.
  2. You can try :

    {% assign metafield-key = collection.title | downcase | prepend: "sf_" %}
    {% assign key = variant.metafields[metafield-key][meta_tag_key] %}
    {% if key == 1 %}
      Do the twist !
    {% endif %}
    
    Login or Signup to reply.
  3. If you working in liquid then you have to use {% %} for defining any variable & also for condition in shopify. You can’t use { this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search