Search code examples
jekyll

Is there any way to access jekyll.environment value in javascript files?


It is easy to check which JEKYLL_ENV is used in templates, but I didn't found a way to get its value in my *.js values, which I think should be very useful. Any ideas on how to achieve this without using inlined tags?


Solution

  • I didn't found a way to access this variable in JS files, so the best way to still use it was utilising window object.

    So I am setting variable in my template with <script> tag like that:

    {% if jekyll.environment == "test" %}
    <script>
      window.testMode = true;
    </script>
    {% endif %}
    

    and then later checking for window.testMode in JS.