What's the most efficient way to set up metafields on Dawn?

Hello!

I am currently setting up a website on Dawn and it has drop downs on the product page for care instructions etc.

I am setting up the metafields for those to function and i am wondering what the most efficient way to do it is.

We have a range of products but we only have 3 different materials, therefore 3 different care guides. Is there a way to set up the dynamic sources for those drop down where I don’t need to copy and paste the care instructions into each product. I would rather just associate a care guide with each product which would allow me to bulk edit the care guides if they ever change.

Thanks,

Ruby

Hi Ruby,

You could set up a single line text product metafield for material type, such as product_info.material. Then you can set your material on each of your products manually, such as “wood,” “metal,” and “plastic.”

Then, within your liquid files, you can build your product guides dynamically by using cases and snippets. Create a snippet for each of your 3 product guides and name them accordingly, such as wood.liquid, metal.liquid, and plastic.liquid. Build the HTML code for each product guide within these snippets.

Then, within your product description liquid code, or wherever you’re wanting to dynamically load the product guides, use the following liquid code as a guide

{% case product.metafield.product_info.material %}
  {% when 'Wood' %}
    {% render 'wood.liquid' %}
  {% when 'Metal' %}
    {% render 'metal.liquid' %}
  {% when 'Plastic' %}
    {% render 'plastic.liquid' %}
{% endcase %}

This approach is dependent on entering the text into the metafield on the product page as exactly as it is in your code, else it won’t work. That being said, you could eliminate this need for precision by instead creating 3 boolean metafields and implementing the code that way.

You’ll create 3 separate boolean product metafields, such as product_material.wood, product_material.metal, and product_material.plastic. You’ll then just need to flip the appropriate switch to “true” on each product page based on what material it is.

You’ll still create your 3 snippet files containing the product guide code, but implementing the loading of these files would look like this instead

{% if product.metafields.product_material.wood %}
  {% render 'wood.liquid' %}
{% else %}
  {% if product.metafields.product_material.metal%}
    {% render 'metal.liquid' %}
  {% else %}
    {% if product.metafields.product_material.plastic%}
      {% render 'plastic.liquid' %}
    {% endif %}
  {% endif %}
{% endif %}

This keeps the code optimized, and will also NOT load any product guide if one of the three metafields is not checked to “true”

Hope that helps, and let me know if you have any questions about implementation