Have your say in Community Polls: What was/is your greatest motivation to start your own business?

How can i create custom metafields for nutrition label

How can i create custom metafields for nutrition label

joaquimoliveira
Visitor
3 0 0

Hello guys,

 

How can i create custom metafields in order to display an HTML CSS styled nutritional table on the product page.

 

My idea is to fill the nutritional metafields on each product page and a table is automatically rendered on the front-end.

 

Thank you very much 

Replies 5 (5)

LitExtension
Shopify Partner
4877 1003 1168

Hi @joaquimoliveira,

With this, I recommend to display images instead of HTML and CSS, it will be simpler for you.

You can follow the steps of the following article: https://community.shopify.com/c/shopify-design/dawn-theme-collapsible-row-with-image-size-chart/td-p...

With step 4 you just change the code to:

<img src="{{ product.metafields.my_fields.size_guide | img_url: 'master' }}" alt="Top Notes" width="530">

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
joaquimoliveira
Visitor
3 0 0

Thanks for the reply but that does not solve my problem because i want the innformation to be crawlable by search engines and i dont want to upload my website with images.

LitExtension
Shopify Partner
4877 1003 1168

Hi @joaquimoliveira,

If you don't want to use images, do you have HTML experience?

Instead of creating Metafields image you can create Metafields text and then add HTML at each product, it will work the same.

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
joaquimoliveira
Visitor
3 0 0

Can i create an HTML table with metafields inside?

Which metafield option do i choose to input a table?

 

thank you

Alan15
Shopify Partner
148 27 72

You could create a product metafield of type text, call it 'ingredients'. For each of your products add a comma separated list of the ingredients to the new metafield (eg. ingredient1, ingredient2, ingredient3,...). Then use this liquid code to display the list of ingredients:

{%- assign ingredients = product.metafields.my_fields.ingredients | split:"," -%}
<table>
{% tablerow ingredient in ingredients cols: 1 %}
{{ ingredient }}
{% endtablerow %}
</table>

 

Then add some css styles for the table.
Have a look at the liquid iterator tags here: https://shopify.dev/api/liquid/tags/iteration-tags#cycle
There's some good options using the 'cycle'  tag for styling.

Need more help? Contact me here