Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access multiple nested variables in Jekyll YAML config

Tags:

yaml

jekyll

I'm building a web page using Poole/Lanyon. A file uses a multi-level or nested site variable like {{ site.github.repo }}.

As a novice in Ruby and YAML, I'm not sure how I should declare this value in _config.yml. I tried like this in _config.yml:

github:
  - repo:  'https://github.com/foo/bar.github.io'

It was not working: an empty string is returned when I use {{ site.github.repo }}. I'm however able to get {{ site.github }} like this: {"repo"=>"https://github.com/foo/bar.github.io"}

In order to use site.github.repo, how should I define this variable in the configuration file?

like image 859
Nullptr Avatar asked Oct 16 '25 18:10

Nullptr


1 Answers

In your _config.yml, you've defined site.github as a list, and you're trying to access it as an associative array, hence the problem.

If you want to access it as an associative array, you'll need to redefine your variable as such:

github:
  repo: 'https://github.com/foo/bar.github.io'

As of writing this, I don't think that the Wikipedia sections I have linked to are super clear, but you can refer to their sample document, which I think showcases YAML's possibilities pretty well.

like image 101
Maxime Kjaer Avatar answered Oct 19 '25 00:10

Maxime Kjaer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!