【问题标题】:How to access multiple nested variables in Jekyll YAML config如何在 Jekyll YAML 配置中访问多个嵌套变量
【发布时间】:2016-02-26 02:14:17
【问题描述】:

我正在使用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,我应该如何在配置文件中定义这个变量?

【问题讨论】:

    标签: yaml jekyll


    【解决方案1】:

    在您的_config.yml 中,您已将site.github 定义为list,并且您试图以associative array 的形式访问它,因此出现了问题。

    如果您想以关联数组的形式访问它,您需要重新定义变量:

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

    在撰写本文时,我认为我链接到的 Wikipedia 部分不是很清楚,但您可以参考他们的 sample document,我认为这很好地展示了 YAML 的可能性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      相关资源
      最近更新 更多