我正在使用 Poole/Lanyon 构建网页. A file使用多级或嵌套站点变量,如 {{ site.github.repo }}
。
作为 Ruby 和 YAML 的新手,我不确定我应该如何在 _config.yml
中声明这个值。我在 _config.yml
中这样尝试过:
github:
- repo: 'https://github.com/foo/bar.github.io'
它不工作:当我使用 {{ site.github.repo }}
时返回一个空字符串。然而,我能够像这样得到 {{ site.github }}
:
{"repo"=>"https://github.com/foo/bar.github.io"}
为了使用site.github.repo
,我应该如何在配置文件中定义这个变量?
最佳答案
在您的 _config.yml
中,您已将 site.github
定义为 list ,并且您正在尝试以 associative array 的形式访问它,因此出现了问题。
如果你想以关联数组的形式访问它,你需要重新定义你的变量:
github:
repo: 'https://github.com/foo/bar.github.io'
在撰写本文时,我认为我链接到的维基百科部分不是非常清楚,但您可以引用他们的 sample document ,我认为它很好地展示了 YAML 的可能性。
关于yaml - 如何在 Jekyll YAML 配置中访问多个嵌套变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33880088/