Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global conditional variables #874

Closed
arslabora opened this issue Jan 21, 2020 · 3 comments
Closed

Global conditional variables #874

arslabora opened this issue Jan 21, 2020 · 3 comments

Comments

@arslabora
Copy link

I have the following code in my templates, for each url:

{% if helpers.environment === "development" %}
        <script src="/assets/js/main.js" defer></script>
    {% else %}
        <script src="{{ site.url }}/assets/js/main.min.js" defer></script>
    {% endif %}

I would like to have tidier templates which uses only something like:
<script src="{{ site.url }}/assets/js/main.min.js" defer></script>
and a global condition that rewrite site.url for production or development environment, like:

if (process.env.ELEVENTY_ENV === 'development') {

        url = "";

    } else {

        url = "https://my.awesome.website";
    }

How can this be accomplished?

Thanks! ;)

@Ryuno-Ki
Copy link
Contributor

You could put a JavaScript file in _data and module export that conditional logic as described in the docs.

@zachleat
Copy link
Member

Howdy y’all! As @Ryuno-Ki noted, this exact example is documented on the JavaScript Data Files docs page.

Thanks!

@zachleat
Copy link
Member

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants