Get Data of Metafield Object from slug

Get Data of Metafield Object from slug

hassaans2008
Visitor
2 0 0

Hey there, I have created a new custom page on shopify and the url of that page is https://domain.com/pages/salt/salt-x

 

Now I want to get data of salt dynamically on to the page through liquid code, but not able to display the data, Please help.

 

hassaans2008_0-1718954774556.png

hassaans2008_1-1718954885285.png

hassaans2008_2-1718954935667.png

hassaans2008_3-1718954964889.png

 

Replies 3 (3)

KieranR
Shopify Partner
401 34 123

Once you've created a metaobject like in your screenshots. 

 

You can view it in the CMS admin: 

KieranR_0-1718967644370.png

 

 

If there is no 'Theme template' assigned to the MetaObject item, there will a button to create one on that screenshot above. It will take you to the theme customizer and ask to create a template. 

 

KieranR_1-1718967965242.png

 

 

You can add sections, connect them to specific metafields, and save it to save the template file for all MetaObject template.

 

You can open that file in theme edit and access see how the section exists in the theme template: 

KieranR_2-1718968197440.png



If you want to edit Liquid/HTML/CSS more directly (I'm assuming you want some kind of custom layout on this page?) then one approach is to create yourself a custom section that can be inserted within the customizer and linked up to the metafields via customizer or through the template json.

 

Be good to know what kind of layout or use-case you are going for here and why that has lead you the need for a custom MetaObject. 

Part time Shopify SEO, based in NZ. Sometimes freelance outside the 9-5.
hassaans2008
Visitor
2 0 0

Please tell me more specifically about how get that Object dynamically in liquid and show the products data after iterating it on the page.

 

Forexample I have been trying following solution:

 

{% assign salt_x_products = shop.metaobjects[request.path].fields['product_salt.products'] %}

{% for product in salt_x_products %}
<div class="product">
<h2>{{ product.title }}</h2>
<p>{{ product.description }}</p>
<img src="{{ product.featured_image | img_url: 'medium' }}" alt="{{ product.title }}">
<p>{{ product.price | money }}</p>
</div>
{% endfor %}

KieranR
Shopify Partner
401 34 123

What is the relationship between the custom meta object "salt x" and products on your site?

 

What are you trying to loop through? Eg products or metaobjects?

Part time Shopify SEO, based in NZ. Sometimes freelance outside the 9-5.