27

Is it possible to setup configuration values within the config.yml file and have them be printed within the HTML page within Jekyll? I would like to set the default title and description of my website within the config.yml file and have them printed out in the header of all my layouts.

matsko
  • 21,895
  • 21
  • 102
  • 144

1 Answers1

46

Every template has a site variable, which contains the settings from _config.yml. For example, if you have something like my_setting: "string" in _config.yml, you can access the value in a template using {{ site.my_setting }}.

Note: if you are using jekyll serve, you will need to restart the process for changes to take place. Indeed, _config.yml is not reloaded with the watch option.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 6
    It's `_config.yml`. +1, though. – Janusz Lenar Dec 21 '12 at 09:59
  • Could somebody explain why this doesn't work for me? I can access the site variable but my custom configurations are not present within the hash. – adamwong246 Nov 11 '13 at 17:59
  • Ok, since I can't edit my answer, I'll answer my own question: Jekyll will use a default configuration if it doesn't find an _config.yml OR you don't supply your own. In my case, the path to the _config.yml file was incorrect. – adamwong246 Nov 11 '13 at 19:08
  • 12
    And here's another - make sure you reload your jekyll serve if you change your _config.yml. (`jekyll serve --watch` doesn't reload config.) – Ross R May 09 '14 at 23:26
  • how to escape html when puting them in config.yml? – andilabs Dec 04 '14 at 10:19
  • is it possible to check site variables in your config using an if blog? `{{% if site.webfont == true %}} blah {{% endif %}}` This doesn't seem to work for me. Blah is printed all the time, regardless of whether site.webfont is true or false. – hallodom Feb 09 '17 at 18:12