Globals

Globals

Globals are special types of metafield values that can be accessed from any file on your theme. You can use these metafields to save values that you’d like to be shared/reused in several pages, products, etc since you’ll only need to enter the value once.

Custom Fields makes it incredibly easy to define globals and you can follow these steps to create your first global:

Step 1: Launch the application

Navigate to the app’s dashboard from Shopify and click on the “Add field” option under the left navigation menu as shown below:

Step 2: Field creation

All the Custom Fields field types are supported, there’s no restriction. Enter the field name and machine name(key) and then select one of the Basic, Advanced, Upload, Reference or Group Fields and then click on “Create New Field”.In this tutorial, we’ll select a text field as shown below:

Step 3: Print the metafield value on your theme

There are various methods that you can use to print the value. If you’d like the raw metafield value, you can use the following liquid code(X represents the metafield key):

{{ shop.metafields.custom_fields[“X"] }}

You could also use an include statement using the default snippet that is generated by the app and print the value using:

{% include 'custom_fields.shop.X' %}

Lastly, you can copy the code displayed on the app’s snippet editor and paste it anywhere on your theme to display the value. You will only need to click on the “Edit code” option to expand the editor as shown below:

Winding up.

Please take a look at the related articles section for some use cases for global fields.