Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi folks - does anyone know how to retrieve JSON data from a Metafield in a Section Block using "dynamic source"
SCENARIO:
We have products which need to display data in a tabular data table. We found it really convenient to add this to each product using JSON in a JSON Metafield.
We now want to display that Tabular Data in a custom Section -> Block -> using this JSON Metafield as the "Dynamic Source"
As of now -> we tried using a Block Input Type = "Text Field" -> but our JSON Metafield is not showing up in the "Dynamic Sources" list. What input field should we be using.
Thanks for your help.
Hi @bgonz,
Do you really need to add it using a block? Why you cannot just place the metafield inside the product or use a liquid block? At this moment, only text metafield can be add dynamically.
Thanks for the reply - I want t make sure I answer you completely:
Do you really need to add it using a block?
No we don't 🙂
But we wanted to expand our knowledge of native Shopify Metafields and take full advantage of the Theme Customerizer using Sections Everywhere with Dynamic Sources. So as we develop out solutions they can be super flexible and future proofed.
Why you cannot just place the metafield inside the product or use a liquid block?
Currently, we just created our Section Block (Shopify Theme 2.0 formatted) to look for a specific metafield name (ex: custom.my-data-table)
custom.my-data-table = JSON Data Input
If custom.my-data-table NOT empty -> loop the data and render in an HTML table accordingly
This seems to work fine - as each product that uses the custom.my-data-table Metafield != EMPTY
will render the Section Block wherever we place it in the Theme Editor.
That being said - I think it would be way cooler -> to allow the Dynamic Data to come from any JSON Metafield the Client creates.
At this moment, only text metafield can be add dynamically.
- To be clear, as far as I know, you can also reference Dynamic Image Input Fields as well. Does anyone know where the documentation on these limitations are?
Hi @bgonz,
I think misunderstood you about the "At this moment, only text metafield can be add dynamically." What I mean by that is currently, in the product page block, you can add a text metafield dynamically, but not adding a file metafield as a block
This metafield allows to render a json data to product page
Data is an JSON object
Code use to console.log
<script>
console.log({{product.metafields.custom.json }})
</script>
I am hoping this graphic explains my question more clearly - my goal is to allow admins to reference any JSON Metafield using the Dynamic Source Icon for Section Blocks as shown below.
I totally agree and just need this feature 😞
Hope shopify will see the sense of making this data more dynamic.
Hi @yotamcuralife,
You can use metaobject nowadays to have a key value pair
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024