Global Section Schema Settings - Access schema across all sections

Hi all,

I’m looking for how to have a global schema that will apply to all sections. Essentially, while each section has it’s own schema, I would like to have a global schema that rolls out across all sections so it doesn’t need to be added to all section schemas manually. Things like rendering a section based on a specific referrer ID, ISOcode, whether user is logged in. I don’t want to need to add this in to every section schema because updating that schema across 20+ sections is a massive waste of time and the schema will always be the same, so is there a schema file I can make that applies an additional global schema to all sections?

Thanks

1 Like

Hello @KyleGriffin

In Shopify, schemas are typically defined within the schema object of individual section files, and there isn’t a native, direct way to create a truly global schema that applies across all sections without adding it to each section’s schema manually. However, you can implement a solution that makes this more manageable by creating a global configuration file or method to handle common logic like referrer IDs, ISO codes, and logged-in users.

Here’s how you can approach this:

  1. Create a Global Schema File
    You can create a global schema file (e.g., global_schema.json or similar) that holds the common settings. This file won’t directly apply to all sections, but you can include the settings from this file in your individual sections using Liquid.

For example, create a file that includes your global logic and settings:

{
  "type": "referrer_id",
  "settings": [
    {
      "type": "text",
      "id": "referrer_id",
      "label": "Referrer ID",
      "default": "default_referrer_id"
    },
    {
      "type": "checkbox",
      "id": "show_for_logged_in",
      "label": "Show for logged-in users only",
      "default": true
    }
  ]
}
  1. Include the Global Settings in Sections Using Liquid
    You can use Liquid in your section files to conditionally render these settings.

For example, within each section schema, you can include the global settings with the help of the settings object.

{% assign global_settings = 'global_schema.json' | file_read %}
{% assign referrer_id = global_settings.referrer_id %}
{% assign show_for_logged_in = global_settings.show_for_logged_in %}

{% if show_for_logged_in == true and customer %}
  
{% else %}
  
{% endif %}
  1. Global Logic in Theme Layout or Snippets
    Instead of adding this logic to every section, you could place some of the logic globally in your theme’s layout files or in snippets.

For example, add logic to your theme.liquid layout file:

{% assign referrer_id = request.referrer %}
{% assign iso_code = request.iso_code %}

{% if customer %}
  
{% endif %}
  1. Custom JavaScript for Client-Side Logic
    If you’re looking to dynamically change the schema or logic based on the user’s referrer, ISO code, or logged-in status, you could achieve some of this on the client-side with JavaScript.

Example:

var referrerId = document.referrer;  // Get referrer URL
var isoCode = navigator.language;   // Get the ISO language code
var isLoggedIn = {{ customer ? 'true' : 'false' }};

if (isLoggedIn) {
  // Logic for logged-in users
} else if (referrerId.includes("specific-website.com")) {
  // Logic based on referrer ID
}

This JavaScript can be placed in your theme layout or a global snippet to be used across all pages.

Conclusion
While Shopify does not support a truly global schema that automatically applies to all sections, using a combination of global configuration files, Liquid includes, and possibly JavaScript can help avoid redundancy and streamline your workflow for common settings like referrer IDs, logged-in checks, or language codes. This approach gives you flexibility without manually adding the same schema to each section.

Thank you :blush:

1 Like

Hi,

Thanks so much for a breakdown of how best to tackle this issue. Much appreciated!

Hopefully they will add this to shopify core functionality in the future. In the meantime, I will try what you’ve suggested on a few key sections and pray its painless going forward!

1 Like

You’re very welcome! I’m glad the breakdown was helpful to you. if you need any help plz let me know :slightly_smiling_face:

Thank you :blush: