Re: Dynamic Block data from JSON Metafield

How to retrieve JSON data from a Metafield in a Section Block using dynamic source?

bgonz
Shopify Partner
3 0 5

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.  

Replies 6 (6)

made4Uo
Shopify Partner
3852 717 1201

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. 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
bgonz
Shopify Partner
3 0 5

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?

made4Uo
Shopify Partner
3852 717 1201

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

made4Uo_1-1665601879393.png

 

Data is an JSON object

made4Uo_2-1665601936829.png

 

Code use to console.log

<script>
  console.log({{product.metafields.custom.json  }})
</script>

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
bgonz
Shopify Partner
3 0 5

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.

 

Screen Shot 2022-10-12 at 2.57.47 PM.png

yotamcuralife
Shopify Partner
7 0 9

I totally agree and just need this feature 😞

Hope shopify will see the sense of making this data more dynamic.

made4Uo
Shopify Partner
3852 717 1201

Hi @yotamcuralife,

 

You can use metaobject nowadays to have a key value pair 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free