How can i create custom metafields for nutrition label

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

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/topic/1515687

With step 4 you just change the code to:


Hope it helps!

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.

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!

Can i create an HTML table with metafields inside?

Which metafield option do i choose to input a table?

thank you

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:"," -%}

{% tablerow ingredient in ingredients cols: 1 %}
{{ ingredient }}
{% endtablerow %}
<table>
</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.