How to create a global variable in shopify?

by darrion.kuhn , in category: PHP CMS , a month ago

How to create a global variable in shopify?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , a month ago

@darrion.kuhn 

In Shopify, you can create a global variable by using the Shopify Theme Editor. Here's how you can create a global variable:

  1. Go to your Shopify Admin dashboard and click on "Online Store" and then "Themes."
  2. Find the theme you want to edit and click on "Actions" and select "Edit code."
  3. In the left-hand sidebar, navigate to the "Config" folder and click on "settings_schema.json" file.
  4. In the "settings_schema.json" file, you can define a new global variable by adding the following code:


{ "name": "Global Variable", "settings": [ { "type": "text", "id": "global_variable_name", "label": "Global Variable Name" } ] }

  1. Save the changes to the "settings_schema.json" file.
  2. Next, navigate to the "Settings" section of your theme editor and you should see the new global variable input field that you just defined.
  3. You can now use this global variable in your theme templates by accessing it through Liquid code like this:


{{ settings.global_variable_name }}


This will output the value of the global variable wherever you place this code in your theme templates.