Access Environment Variable Overrides within snippets

Hi All,

This took me a while to figure out, and there didn’t seem to be any examples around the interwebs so I thought I’d post my solution.

In order to access the environment variables that you have set in your preferences, add this to the top of your snippet and make sure that the ‘Treat as EJS’ option is checked.

<%
var getEnvirons = ko.interpolate.interpolateString(["%(pref:userEnvironmentStartupOverride)"]);
var elements = getEnvirons.split ("\n");
var Environ = {};
for(var i in elements) { 
    var key = elements[i].split("=");
    if (key.length > 1) {
      Environ[key[0]] = key[1];
    }
}
%>

You can then access a specific variable by using <%= Environ['variable name'] %>

I hope this is of help to those that need it :slight_smile:

3 Likes

Thanks @djandiek! Great advice and a perfect use-case for EJS.