All things Shopify and commerce
I am using metaObjects in shopify. I have created a metaObject name "Projects" . I created a page "Projects" to display those saved projects through liquid code. It is working as per the requirment on Projects page but now i want to display each project detail on single page. How do i approach this ? Like should i create a page and set a template on it and in that template , fetch the metaobject handle to display its details . I am facing issue like how do i call the same single page for all projects details and display its details. Can someone please guide what is the possible way to get each metaObject values on single project page .
Thanks
I am searching for the exact same thing. Have you got anything?
me2me2me2 - any answer or hint much appreciated
this is what worked for me:
https://community.shopify.com/c/notes/privatenotespage/tab/inbox/note-id/161782/notes-view-mode/sing...
Ok I see, so first I wanna make sure this solution is coming from Dock3r (https://community.shopify.com/c/user/viewprofilepage/user-id/1442260)
and I appreciate a lot his solution. It helped me to have it solved. I hope Dock3r is good with posting his solution in here
Quoting from here on from my conversation with Dock3r:
Hi,
The stackoverflow article takes some time to write but I think you are in a hurry.
I have a meta object called iro (it means writer in my language). Every product has one or more writer metaobject related to it.
You will find a couple of console.log lines for debug purposes. Just ignore and delete them If you don't need anymore.
Single page of writer
<script>console.log({{ request.path | split: "/" | last | json }});</script>
{% assign writer_handle_url = request.path | split: "/" | last %}
{% assign writers = shop.metaobjects.iro.values %}
{% assign writer = shop.metaobjects.iro.values | where: 'handle', writer_handle %}
{% for a_writer in writers %}
<script>console.log({{ a_writer.system.handle | json }});</script>
{% if a_writer.system.handle == writer_handle_url %}
{% assign writer = a_writer %}
{% break %}
{% endif %}
{% endfor %}
<script>console.log({{ writers | json }});</script>
<div class="designer-container">
<div class="designer-body">
<h2 class="h1">{{ writer.nev }}</h2>
<p class="designer-text">{{ writer.leiras | metafield_tag }}</p>
</div>
</div>
List page of writers
<script>console.log({{ shop.metaobjects.iro.values | json }});</script>
{% for writer in shop.metaobjects.iro.values %}
<script>console.log({{ writer | json }});</script>
<script>console.log({{ writer.system.handle | json }});</script>
<div class="designer-container">
<div class="designer-body">
<h2 class="h1">{{ writer.nev }}</h2>
<a href="/pages/iro/{{ writer.system.handle }}" class="button button--primary">Bővebben az íróról</a>
</div>
</div>
{% endfor %}
I tried and succeeded!
Here's my solution
- Assume we have a metaobject called movies , create some entries
- Create a file named 'page.movies.liquid' in the templates directory
- Now, let's create a page called 'Movies' and set its template to 'movies'
- Finally, add the following code into the 'page.movies.liquid' file
{% section 'movies-in-collection' %}
{% assign movie_handle = request.path | split: '/' | last %}
{% assign movie = shop.metaobjects.movies[movie_handle] %}
<script>
console.log({{ shop.metaobjects.movies.values | json }})
console.log({{ movie | json }})
</script>
<p>Handle {{ movie_handle }}</p>
<h2>
{{ movie.title }}
</h2>
references:
request object
I hope this helps!
This is solved for me now by Shopify. They have introduced Metaobject page templates, you can create a template to display your different metaobject entries: https://shopify.dev/docs/themes/architecture/templates/metaobject
In addition, I think it's worth mentioning that to reference the metaobject associated with the page using liquid, one can use:
{{ metaobject.field_name }}
Whilst obvious once understood, for some reason does not appear to be clearly stated anywhere.
It's okay @m1ch43l . Thanks for posting it here. I was originally going to write a more illustrative example but unfortunately I never got around to it.
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