如何在 Jekyll YAML 配置中访问多个嵌套变量
How to access multiple nested variables in Jekyll YAML config
我正在使用 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, and you're trying to access it as an associative array,因此出现了问题。
如果您想将其作为关联数组访问,您需要重新定义变量:
github:
repo: 'https://github.com/foo/bar.github.io'
在撰写本文时,我认为我链接到的维基百科部分不是非常清楚,但您可以参考它们 sample document,我认为它很好地展示了 YAML 的可能性。
我正在使用 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, and you're trying to access it as an associative array,因此出现了问题。
如果您想将其作为关联数组访问,您需要重新定义变量:
github:
repo: 'https://github.com/foo/bar.github.io'
在撰写本文时,我认为我链接到的维基百科部分不是非常清楚,但您可以参考它们 sample document,我认为它很好地展示了 YAML 的可能性。