I would like to create one global variable (a constant value that rarely changes) that can be accessed in different pages, like the home page, cart, articles, product pages, and different sections, like header and footers, and more. Metafields seem to be too restrictive. Not sure if there is some liquid data that could have a constant value that can be accessed in the above-mentioned areas. I’d appreciate any help in this regard. I am able to modify the theme code, but I don’t have any app dev experience, so hopefully, that is not required.
Shopifys liquid theme architecture is not conducive to custom “global” variables.
Easiest for the inexperienced is to just create a metafield on the shop object that is then assigned to a variable to reference it in each context that needs it.
Or otherwise you could put it on something like a page/product/collection that could end up easily being deleted not remembering it was really only a stub for something more important for the frontends theme code .
More advanced is refactoring the theme due to scoping turn all {% render %} tags into {% includes %} , or obsessively pass the need variable as a parameter in every {% render %} tag ; and set the variable in each section I think for OS.20 JSON templates( I haven’t had need to test this situation) . For more research the forums for similar topics on those tags and globals limitations about passing around global variables.