Accessing Fields in Non-Standard Templates

If you'd like to use your fields in non-standard places or templates, most of the time those templates won't have the product or other object in scope, so you'll need to adjust your code from our examples.

Printing Home Page Fields

If you want to print fields attached to the home page, from index.liquid try this:

Instead of calling {{ page.metafields.custom_fields["YOUR FIELD"] }} call it this way: {{ pages.frontpage.metafields.custom_fields["YOUR FIELD"] }}

Printing Product Data For Any Product, Anywhere

When you have a product in scope but want to access your Custom Fields (maybe while looping products, for example):

{{ all_products[product-handle].metafields.custom_fields["YOUR FIELD"] }}

When you want a specific product's fields:

{{ all_products["YOUR HARDCODED PRODUCT HANDLE"].metafields.custom_fields["YOUR_FIELD"] }}

Printing Collection Fields, Anywhere

Use this for when you want to access a Collection Field in a non-standard template eg. Products: 


Additional Resources

See to learn about how to use handles to access information on objects that are not currently in scope.

See to learn about how to use the all_products variable in liquid.