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:
- 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
}
]
}
- 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 %}
- 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 %}
- 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 