【问题标题】:In Jekyll, do all variables have to be defined in _config.yml?在 Jekyll 中,所有变量都必须在 _config.yml 中定义吗?
【发布时间】:2014-10-19 01:10:49
【问题描述】:

在我的 Jekyll _config.yml 文件中,我有:

...
test1: hello
...

在我的 index.html 文件中,我有

...
<h1>{{ site.test1 }}</h1>
...

当我的网站建成后,在 _site/index.html 中,我现在有了

...
<h1>hello</h1>
...

这是我想要做的:在我的 _config.yml 文件中:

...
test1: hello
@include _config2.yml ### this is not possible, but I'd like to do this!
...

然后,在_config2.yml:

...
test2: world
...

在 index.html 中,

...
<h1>{{ site.test1 }}, {{ site.test2 }}</h1>
...

会在 _site/index.html 中生成:

当我的网站建成后,在 _site/index.html 中,我现在有了

...
<h1>hello, world</h1>
...

我试图弄清楚如何/如果可以做到这一点,我的想法是我有一个包含数十个变量的单页网站,为了我的编辑,我希望他们分开.yml 文件。

干杯,

阿尔伯特

【问题讨论】:

  • 我自己对 Jekyll 来说还很陌生,但这似乎是数据文件的完美案例。 jekyllrb.com/docs/datafiles
  • 谢谢,这就是我要找的!
  • 太棒了!我也发布了答案。您能否将其标记为已批准的答案以帮助未来的访客?谢谢!

标签: jekyll


【解决方案1】:

Jekyll 提供了使用可在您的页面和帖子中使用的数据文件的选项。这对他们来说是一个完美的案例。

更多信息在这里:http://jekyllrb.com/docs/datafiles/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 2022-07-12
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多