Sachin Jain
Sachin Jain

Reputation: 21842

Defining Variable Configuration in _config.yml in jekyll powered website

There are multiple sets of configuration which you may want to execute when you are running the site locally while when your site is running on server (say Github).

I have defined similar set of configuration in my _config.yml file like this

title: Requestly
locale: en_US
description: Chrome Extension to modify HTTP(s) Requests
logo: site-logo.png
search: true
env: dev

config:
  dev:
    url: http://localhost:4000
  prod:
    url: http://requestly.github.io/blog

url: site.config[site.env].url // Does not work

I have used {{ site.url }} everywhere else in my templates, layouts and posts.

How can I define site.url in my _config.yml file whose value depends upon the config and env defined in the same file.

PS: I know one of the ways is to change {{ site.url }} to {{ site.config[site.env].url }} in all the files. That should probably work.

I just want to know how to use variables in _config.yml. Is that even possible ?

Upvotes: 3

Views: 2363

Answers (2)

Giang Phạm
Giang Phạm

Reputation: 55

Yes you can with Jekyll 3.8.0 or later version now. Please give that a try

Upvotes: 0

David Jacquel
David Jacquel

Reputation: 52799

No you cannot use variables in a _config file.

You can find more informations here : Change site.url to localhost during jekyll local development

Upvotes: 2

Related Questions