I’m using trying to display shopify content based on the local domain it’s using. To do this I’ve got the below which works fine:
{% if request.host contains 'co.nz' %}
{% assign site_currency = "NZ" %}
{% endif %}
The problem is that variables seem to only work within the one snippet/template/layout file prior to being compiled, and what Shopify classes as a global variable is in fact just a value from the theme settings and therefore can’t be conditional.
I’ve tried ‘{% assign scope = ‘page’ %}’ which apparently works after compilation but I can’t get it to work and there’s very little documentation.
Does anyone know how I can declare this variable just once and then reference it throughout my theme?
Thanks!
2
Answers
Shopify global variables are only the objects specified here – https://shopify.dev/docs/themes/liquid/reference/objects
Only way to acheieve a global reference functionality without referencing through snippets is by storing it in the
cart.attributes
via JS, but that requires a page refresh to take effect.Create a snippet or just paste the code above
{{ content_for_layout }}
intheme.liquid
If you have few different currencies I suggest that you look into using
case/when
, here are the docs.