W3cubDocs

/Jekyll 4

Environments

In the build (or serve) arguments, you can specify a Jekyll environment and value. The build will then apply this value in any conditional statements in your content.

For example, suppose you set this conditional statement in your code:

{% if jekyll.environment == "production" %}
   {% include disqus.html %}
{% endif %}

When you build your Jekyll site, the content inside the if statement won’t be run unless you also specify a production environment in the build command, like this:

JEKYLL_ENV=production jekyll build

Specifying an environment value allows you to make certain content available only within specific environments.

The default value for JEKYLL_ENV is development. Therefore if you omit JEKYLL_ENV from the build arguments, the default value will be JEKYLL_ENV=development. Any content inside {% if jekyll.environment == "development" %} tags will automatically appear in the build.

Your environment values can be anything you want (not just development or production). Some elements you might want to hide in development environments include Disqus comment forms or Google Analytics. Conversely, you might want to expose an “Edit me in GitHub” button in a development environment but not include it in production environments.

By specifying the option in the build command, you avoid having to change values in your configuration files when moving from one environment to another.

To switch part of your config settings depending on the environment, use the build command option, for example --config _config.yml,_config_development.yml. Settings in later files override settings in earlier files.

© 2020 Jekyll Core Team and contributors
Licensed under the MIT license.
https://jekyllrb.com/docs/configuration/environments/