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
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024