Reference field types

A reference type custom field is a specialized version of a 'Selection' type which will list all available objects of its type: 

Once a value is selected, the metafield will contain the referenced Shopify object's handle as its value (see special case for variant reference fields below).You can use this handle as a reference to a Shopify object via a Liquid global object depending on the type.

{{ blogs[product.metafields.accentuate.related_blog].title }}  
{{ articles[product.metafields.accentuate.related_article].title }}  
{{ page[product.metafields.accentuate.related_page].title }}  
{{ collections[product.metafields.accentuate.related_collection].title }}  
{{ all_products[product.metafields.accentuate.related_product].title }}  
{{ linklists[product.metafields.accentuate.related_linklist].links }}

The above examples use Shopify Global Objects

Note: Shopify global objects only return values for published products, collections, pages etc. Also, Shopify imposes a restriction on how many calls to "all_products" you can make from a single Liquid page. This is currently set to 20 unique handles per page

Using reference types, we can also get the metafields from the referenced objects using the handle. This is just as easy as getting the url or title as shown above.

{{ all_products[product.metafields.accentuate.related_product].metafields.accentuate.isbn }}	

Variant reference fields

In Shopify, individual product variants don't have handles, so we need to rely on the product's handle combined with the id of the referenced variant. Therefore variant references are stored as product_handle:variant_id for easy access to both the product object and the underlying variant, like this:

{% assign product_handle = product.metafields.accentuate.referenced_variant | split: ':' | first %}
{% assign variant_id = product.metafields.accentuate.referenced_variant | split: ':' | last | plus: 0 %}

{% assign referenced_product = all_products[product_handle] %}
{% assign referenced_variant = referenced_product.variants | where: "id", variant_id | first %}

The referenced variant is {{ referenced_product.title }} {{ referenced_variant.title }}

Note the use of the Liquid filter "plus: 0" which converts a string to a number for use in the "where" filter.

Multiple selections

As is the case for the basic type 'Selection', if you have opted for multiple selections for your reference type, each object's handle is listed with the "pipe" symbol ("|") as a separator token. You can use Liquid's 'split' filter on the metafield to separate the handles - like this:

{% assign selected_handles = product.metafields.accentuate.selection | split: '|' %}
{% for selected_handle in selected_handles %}
  <p><a href="{{ all_products[selected_handle].url }}">{{ all_products[selected_handle].title }}</a></p>
{% endfor %}	
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us