Metaobjects

A general guide to understanding metaobjects that links you to our other articles on the topic

This page will explain what metaobjects are, how they differ from metafields and how to most effectively use them.

Metaobjects are a great way to store and manage data that does not belong directly on any pre-existing scope, but is instead self sufficient and has meaning by itself. You can think of one metaobject definition like a standalone scope that can function by itself. An example of a standalone scope would be products, or pages. Each one of these scopes contains information that is organised neatly into a template. For products that would be: Product title, description, media, price, inventory and all the additional data you may have attached to them using metafields.

Metaobjects come into play when you need to create self sufficient groups of information that fit neatly into templates. A great example of this would be Authors.

Lets say you run a book store and want to organise all your authors properly, or you have an extensive blog on your store that is run by multiple people and you want to avoid having to write out all of the information about the author every time you publish a blog or add a new book. The ideal way to solve organise this data is by using metaobjects. This would provide you with a convenient template you can use to add new, or easily edit and manage your authors.

Some of you probably thought about an approach to solve this using metafields. While metafields are a powerful tool to attach data to pre-existing structures like products (books in our case) or blogs. Creating the author template on products using metafields would look something like this:

It would work, but it would lead to the author data being bound to its book which would result in you having to add all the author data again every time you add a new book (or blog post). Luckily metafields can also reference metaobjects, so you can have the best of both worlds - the superior data organisation of metaobjects, and the specificity of metafields.

In this approach we group the 4 fields we had into one template, and every time we want to add a new author we can do so by pumping out another metaobject instance. In this approach adding a book whose author is already created is as easy as pointing. Also if you wanted to display the author itself this approach enables that as well, while that would be hard to do taking the other route. Editing an author’s data is also made easier this way since you can edit it in one place and it would update everywhere instead of having to go trough all the author’s books and editing each one.

As you can see this fundamentally changes the position of the author. Instead of being bound to a book it is a entity that functions by itself. This is the moment when metaobjects shine the brightest.

Last updated