Shopify themes, liquid, logos, and UX
Hi I'm using the new collection metafields to add some extra content on collection pages.
All works as expected except for the rich text metafield.
When I use
{% if collection.metafields.custom.collection_quick_links.value %}
{{ collection.metafields.custom.collection_quick_links.value }}
{% endif %}
This outputs raw JSON to the page, what I want is to output the HTML from the rich text metafield.
Any ideas?
Solved! Go to the solution
This is an accepted solution.
Figured it out, needed a metafield filter for some reason, not sure why some metafields need these for output and some don't? Just need to add
{{ collection.metafields.custom.collection_quick_links.value | metafield_tag }}
This is an accepted solution.
Figured it out, needed a metafield filter for some reason, not sure why some metafields need these for output and some don't? Just need to add
{{ collection.metafields.custom.collection_quick_links.value | metafield_tag }}
Don't work for me unfortunately. I get the error:
metafield_tag can only be used with a metafield drop
This is a metafield Rich Text for a collection. When I remove | metafield_tag it just show the JSON indeed. Any help?
I think you need to remove ".value"
This will work:
{{ product.metafields.custom.field | metafield_tag }}
But this won't:
{{ product.metafields.custom.field.value | metafield_tag }}
thanks so much
Thanks!
A solution/npm package, for anyone look for converting a Metaobject's rich text type to HTML using Javascript (i.e. you are querying the Metaobject using the storefront API or using Hydrogen. I built the package to make it super easy to convert it Shopify rich text AST to HTML.
I am posting this in this thread as I had searched for a Shopify Official solution far and wide without success ( one would think they would have one since they must be converting it themselves internally. So I just had to build it myself. We have been using it since internally since Feb. without any issues. Hopefully this is helpful for those looking far and wide as I did.
NPM Package:
shopify-rich-text-renderer
Rich Text type:-
metafield_tag filter is specifically needed for rich text metafields in Shopify.
Rich text metafields store formatted text content, including HTML tags for elements like paragraphs, bold text, or lists.
The metafield_tag filter acts as a parser, interpreting these HTML tags and converting them into the actual formatted text you see on the storefront.
Other types:-
All other metafield types don't contain HTML tags, so there's no need for parsing or rendering with metafield_tag. The data is presented directly based on its type.
I am surprised this is not mentioned in any docs as far as i am aware.
Hey @mcqua007,
I can’t agree with you more. Liquid filters would normally the last place I will dig through if I cannot access the correct format no matter how. This one in particular what stops us from putting it on the liquid api metafield / metaobject docs?
Another thing I never feel clear enough is between the type definition in liquid schema and metafield data source types. For instance I want some html from metafield data source and render as it is in liquid. Which type in metafield for the field (likely rich text area or multi lines text) and which type in liquid schema (rich-text)? How may I make them compatible with each other so that I can use the dynamic data source in Customizer?
And don’t even mention the headless communication with metafield yes it requires a package to do the conversion.
lastly please allow me to double ask, what’s the point of not to output html from rich text field?
Hello @alexmorris
It's GemPages support team and glad to support you today.
You can try with the following code:
{% if collection.metafields.custom.collection_quick_links.value %}
{{ collection.metafields.custom.collection_quick_links.value | metafield_tag }}
{% endif %}
Hope my solution can work and support you!
Kind & Best regards!
GemPages Support Team.
Is there a way to iterate through children of rich_text_field?
Something like this (my code doesn't work) could be useful to build a per-product FAQ, building accordion interface around the parsed rich-text:
{% for item in product.metafields.custom.faq.children %}
{% if item.type == 'heading' %}
{% comment %} Print HTML for heading {% endcomment %}
<h4>{{ item.children[0].value }}</h4>
{% endif %}
{% if item.type == 'paragraph' %}
{% comment %} Print HTML for paragraphs {% endcomment %}
<p>{{ item.children[0].value }}</p>
{% endif %}
{% endfor %}
The above worked for me. Is this referenced on the Shopify docs anywhere?
Hi Devlife, should be better documented indeed.
https://shopify.dev/docs/api/liquid/filters/metafield_tag
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025