Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we use environment variables in a Jekyll config file?

Tags:

bash

ruby

jekyll

Is there a way I can use one my bash environment variable (say $FOO) in my Jekyll's _config.yml file?

I've tried using:

foo = <%= ENV['FOO'] %>

But it didn't work as the Ruby code wasn't interpreted.

Versions used:

  • Ruby: 2.1.2
  • Jekyll: 2.5.3
like image 906
Dirty Henry Avatar asked Apr 26 '16 13:04

Dirty Henry


People also ask

How do you put environmental variables in web config?

For Applications, including Web Applications, On Windows: If you want environmental variables to be expanded your application will need to do that itself. A common way of doing this is to use the cmd syntax %variable% and then using Environment. ExpandEnvironmentVariables to expand them.

How do you use environment variables?

In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable. Click Edit to modify an existing environment variable.

Can I use variables in .env file?

The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.


1 Answers

If your goal is to use environment variables as liquid items {{ site.something }}, you might be able to get this thing in your Gemfile a go:

gem 'jekyll-environment-variables', group: :jekyll_plugins

And then you'll be able to use {{ site.env.HOME }} and expect it be converted to something like /home/ubuntu in the output HTML.

Disclosure: I am the owner of the gem and I've been using it personally since long ago.

like image 148
iBug Avatar answered Oct 10 '22 03:10

iBug