How do i get MetaObject values on single MetaObject Page

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

3 Likes

Hey @ma92 , have you found any solution for this ?

1 Like

I am searching for the exact same thing. Have you got anything?

me2me2me2 - any answer or hint much appreciated

Any ideas on this?

this is what worked for me:
https://community.shopify.com/c/notes/privatenotespage/tab/inbox/note-id/161782/notes-view-mode/single

Hi @m1ch43l , thanks for the reply.

I can’t open that link. Could you paste the text in here or check the link?

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


{% 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 %}

  {% if a_writer.system.handle == writer_handle_url %}
    {% assign writer = a_writer %}
    {% break %}
  {% endif %}
{% endfor %}

  

      ## {{ writer.nev }}
      

{{ writer.leiras | metafield_tag }}

  

List page of writers


{%  for writer in shop.metaobjects.iro.values  %}

  

  

      ## {{ writer.nev }}
      Bővebben az íróról
  

{% endfor %}

Thanks @m1ch43l and @dock3r .

Does this solve the issue of having to create multiple single writer pages. If it does how do you create the template to display the “Single page of writer” code? Sorry if I am missing something obvious here

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] %}

Handle {{ movie_handle }}

## 
{{ movie.title }}

references:
request object

get metaobject by it handle

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

1 Like

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.

1 Like

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.

1 Like