Shopify themes, liquid, logos, and UX
My store sells appliances which each have multiple PDF documents we need to make available for download. To this end, I have defined two metaobjects in our store:
Currently, I am trying to set up a page template for the document_set metaobject, so that we can provide our customers with a link to a page that includes all of documents they need. Initially, my plan was to access the Metaobject list on document_set, and then iterate through it to display the text and thumbnails for all of the document metaobjects in the set.
In the process of setting this up however, I discovered a mysterious feature that I can't find information about anywhere. When I connected the dynamic source to my custom content block, I had the option to choose documents, which is the name of the Metaobject list that contains all of the individual document metaobjects I needed to list. When I added this dynamic source, the icon for the block changed to the cyclical arrows seen in the screenshot, and the preview showed two copies of the HTML code (one copy for each document I have in the document_set.documents list).
This is fantastic, as it implies that Shopify has identified the dynamic source as an array, and is automatically iterating through the list to output a layout block for each entry. My issue unfortunately is that I have NO IDEA how to reference the current object in the list and display its metafields.
I did some investigation to see what was providing this iterator functionality in the hope that I could find documentation. In the page source, the cyclical arrow icon is referred to as a "repeater", and the page template JSON for this block contains a key called "repeater" with its value set to "{{ metaobject.documents.value }}" (a reference to the Metaobject list I am trying to iterate over).
So although I can tell that this feature is called a "repeater", I can't find any info or documentation anywhere for how it works. It doesn't seem to be a part of the Expanse theme I'm using, and I suspect that it is an undocumented part of Shopify itself. Does anyone have any info on this special form of block generation for list metafields? If not then I can go back to my original plan to simply write a for loop iterator, but this feature seems much more elegant and I'd like to learn how it works.
Hi @BFWebTeam, did you ever get an answer for this?
I've been working with trying to iterate through the Metaobjects list reference from a metafield, and just was able to print out the proper data onto a liquid section. I had tried those dynamic sources through section blocks, but found it problematic.
I am putting up specific "slides" of a client's products on individual pages, and want that info to be dynamic per page. So I set up a page metafield name space and added a metaobject definition "slide" that has a number of entries the page metafield can select from. So the metafield "slides" was a list of metaobjects. I was able to pull those objects by iterating through the value key of that metafield array.
{% for slide in page.metafields.info.slides.value %}
<h3>{{ slide.title }} </h3>
{% endfor %}
This page here was key to helping me figure out the nuances of those objects. Previously, just printing out "page.metafields.info.slides" showed a list of graphQL references that I couldn't even iterate through. I think the trick is seeing it as a LIST type (which may be your "repeater" suspect), and having to access the value (not values) of that list in order to access the data.
Hoping this helps?
Ah yes, I too have had to learn the nuances of Liquid arrays. They are frustratingly limited and hard to use. To clarify, I am familiar with using the value accessor method you described, and I was able to accomplish my goal through that method. I simply made this post to try and find information about this mysterious "repeater" function that I stumbled across.
I'll use your metafield as an example of what I mean. If you add page.metafields.info.slides as a dynamic source for a content block, the editor will recognize it as an array. If that content block can have multiple items in it, then Shopify will output a content item for each slide, as if you had used {% for slide in page.metafields.info.slides %}. This behavior is the "repeater" function I'm referring to. My problem is that there's no way for me to know what the value of slide is, and the repeater is therefore useless without being able to access the properties of individual items in the array.
I was hoping that a Shopify staff member might pop in and provide details about this undocumented behavior, but no dice. Maybe it's a new feature that they haven't perfected yet?
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024