Detect localhost, staging or production and access env vars in liquid

I’m trying to do the same thing. The closest I’ve gotten is conditionally defining a global JS variable.

In the site , do something like this:


Then you can reference dataApiBaseUrl anywhere else (script tags or JS files included on the page). This is also handy for exposing theme settings to JS.

But I wish there was a way to do this with Liquid so we could do things like load different versions of third-party scripts:

{% if environment == 'development' %}
  
{% else %}
  
{% endif %}

Sadly I haven’t found a way to do that, so I may need to do it in our deploy script, which is kind of a pain.

1 Like