Shopify themes, liquid, logos, and UX
Hi There
I'm trying to build a store for a client and use metaobjects to create some 'website' content for them.
I have two metaobjects that I want to reference each other and display content from each other on their respective web pages.
The first one is for releases - this displays information for product releases
The other is videos which displays product videos.
What I need is to show videos on the releases page. I've created a metaobject which allows me to apply the videos to the release;
I've tried {{ metaobjects.videos }} which returns the shopify g://ids but cannot find any way to access the metaobjects data - I've tried many different variations of the forloop to try and access it.
Does anyone know any way to access this data - would be odd to let us reference other metaobjects on a metaobject if we can't loop through and display the info on a page.
Sean
But I can't work out how to reference these in the liquid.
Hi @SeanieB1983 ,
You're on the right track by using metaobjects, but accessing and looping through them requires a bit of structure in your Liquid code. To display the data from your video's metaobject on the release page, you need to:
1. Access the correct metaobject: If {{ metaobjects.videos }} is returning the g://ids, you’ll want to use those IDs to fetch the actual data from the metaobject.
2. Loop through the metaobjects: You can loop through the metaobject data by fetching the referenced metaobject entries based on the g://ids. Here's an example approach:
{% for video_id in metaobject_field_name %}
{% assign video = shop.metaobjects.videos[video_id] %}
<div>
<h2>{{ video.title }}</h2>
<video controls>
<source src="{{ video.video_url }}" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
{% endfor %}
Replace "metaobject_field_name" with the actual field name for your videos in the "releases" metaobject. This code loops through the IDs, fetches each video metaobject by its ID, and displays the data on the page.
I hope this helps! If it does, please like it and mark it as a solution!
If you need further assistance, feel free to reach out!
Regards,
Sweans
Hi Sweans
Thanks for getting back to me, unfortunately, still struggling to return any values.
Here's the info for releases metafield that references the videos;
Here's the videos metafield
Have tried a few variations, am I misunderstandng;
<!-- One -->
{% for video_id in metaobject.videos %}
{% assign video = shop.metaobjects.videos[video_id] %}
<div>
<h2>{{ video.title }}</h2>
</div>
{% endfor %}
<!-- Two -->
{% for video_id in metaobject.videos.values %}
{% assign video = shop.metaobjects.videos[video_id] %}
<div>
<h2>{{ video.title }}</h2>
</div>
{% endfor %}
<!-- Three -->
{% for video_id in shop.metaobject.videos.values %}
{% assign video = shop.metaobjects.videos[video_id] %}
<div>
<h2>{{ video.title }}</h2>
</div>
{% endfor %}
Any direction is greatly appreciated!
Sean
Hi SeanieB1983,
Thank you for sharing the screenshots! It looks like the issue is related to how you're referencing the videos metafield data.
Here's an approach that should work:
{% for video_ref in metaobject.videos.values %}
{% assign video = shop.metaobjects.videos[video_ref] %}
<div>
<h2>{{ video.title }}</h2>
</div>
{% endfor %}
Explanation:
Using this approach should allow you to pull in the correct video title from your videos metaobject.
I hope this helps! If it does, please like it and mark it as a solution!
If you need further assistance, feel free to reach out!
Regards,
Sweans
Sorry, still not working. Does it make a difference that its in the metaobject template in the theme editor;
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024