What syntax should I use to add a metaobject type in input setting schema?

What syntax should I use to add a metaobject type in input setting schema?

gduverger
Tourist
6 0 8

In my Liquid template, in {% schema %}, I want to add an input setting that references a metaobject.

 

What should the syntax be?

 

I tried,

 

{% schema %}
{
"settings": [
        {
            "type": "testimonial",
            "id": "testimonial"
        }
]
}
{% endschema %}

 

 

And,

 

{
            "type": "shop.metaobjects.testimonial",
            "id": "testimonial"
        }

 

 

As well as,

 

{
            "type": "{{ shop.metaobjects.testimonial }}",
            "id": "testimonial"
        }

 

and a bunch of other syntaxes.

 

I read this doc https://shopify.dev/docs/api/liquid/objects/metaobject but I guess it's still not clear to me.

 

I keep getting an “Unable to update the file” error.

 

Any thoughts?

 

Replies 4 (4)

yadrienne
Shopify Partner
2 0 1

hi, Gduverger, I have the same issue, die you have already the solution? could you please share? thank you in advance!

gduverger
Tourist
6 0 8

No solutions, yet. Sorry.

KS_Callum
Shopify Partner
1 0 0

Hey Gdruverger,

Better late than never but if you haven't found out already you need to use a type of "url" and then select dynamic source. 

https://shopify.dev/docs/themes/architecture/settings/input-settings#url

 

KS_Callum_0-1690162313602.png

The field should appear as this in the theme editor. 

KS_Callum_1-1690162399984.png

 

From there click the highlighted button and either select a metafield or click the link to add a new metafield.

 

 

Elizabeth_craig
Shopify Partner
14 2 9

I've been looking for similar functionality. I don't think there is a direct solution. From what I understand, there is no schema setting type metaobject. Maybe Shopify will add that in the future. For now, there are a few workaround solutions I could think of.

 

The most direct method, I think, is to use a Custom Liquid section and input your metaobject reference code there. This would require the admin to input some code, or not touch this section. 

 

As another method example, I made a setting in my section schema for a regular text input field. I use this text field to capture the handle of the metaobject I'd like to reference. So if you know the metaobject's handle, you can access it! I suppose you could also try to access it with other information about the metaobject, but the handle seems like the most direct way. With this method, you can change the metaobject selected from the Customize admin screen, but you'll need to know the metaobject handle.

 

Another way that I saw in a YouTube video, is to add a metafield to a page. This metafield can reference a list of metaobjects, and then your section can loop through the list of metaobjects. With this method, you'd have to add the metaobjects to the metafield from the Page admin screen. This wouldn't work on the home page, since the home page does not have metafields, like Pages do.

 

You could also possibly add an additional entry in your metafield definition, like a true/false type, to sort of enable or disable the metaobject. For example, if you have 20 testimonial type metaobjects, but only want to display 5 specific ones, then you would set the new true/false entry to true for those 5. In your theme code, you would loop through all of the testimonial metaobjects, then display only the ones that are 'enabled'.

 

There may be more workarounds. I hope Shopify adds a more direct method. Metaobjects are still pretty new.

 

Edit: Thought of another method! You could create a new metobject definition, called something like 'Display Testimonials'. Then add a metaobject field in the metaobject definition that accepts a list of entries. Then you'll be able to select which metaobjects, in this case testimonials, you would want to reference in the 'Display Testimonials' metaobject. And then, you would reference the metaobject 'Display Testimonials' in a section of custom liquid, or even hardcoded in your theme code. This would hide it from the admin!