【问题标题】:Set global variables inside a Jekyll template在 Jekyll 模板中设置全局变量
【发布时间】:2014-01-28 13:47:52
【问题描述】:

我在 Jekyll 配置中定义了以下内容:

dir: a-directory/

我现在想要:

dir: a-directory/
images: {{ dir }}images/

但是这行不通。一种解决方案是将其放在我的模板文件中

{% capture images %}{{ site.dir }}images/{% endcapture %}

变量图像现在可用于该文件中的其他点。但是,它不适用于与该文件一起编译的任何内容,例如我的实际页面。

执行{% capture site.images %} 似乎是对它进行排序的方法,但您不能将项目分别分配给 _config 和 front matter 之外的 sitepage 全局变量。

有没有可能实现这种全局变量堆叠?

(请避免涉及更改我的目录结构的解决方案;如果有类似的编译器提供更多功能而不会对工作流程进行巨大更改,我愿意)

【问题讨论】:

    标签: compilation global-variables jekyll


    【解决方案1】:

    YAML 似乎不直接支持串联。不过,有一些解决方法:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 1970-01-01
      相关资源
      最近更新 更多