【发布时间】:2013-08-29 15:09:33
【问题描述】:
这个让我难过...
我想在其他几个 Jekyll 页面之间共享来自单个文件的 YAML 哈希。
我知道你可以将它放在 Front Matter 中(这需要复制它),我知道你可以通过插件生成(编写)页面(但我在几种不同类型的页面中使用它,其中会很复杂)。也不是我想要的。
我想在我的页面中循环使用 Liquid 的散列,但我似乎无法从插件获取散列到 Liquid。 {% capture %} 仅适用于字符串,{% assign %} 不会让您在其内部调用标签,例如 {% assign projects = gethash %} 其中 gethash 是自定义 Liquid 标签。
基本上,我想使用单独的 YAML 文件,如基于文本的数据库。
YAML 文件中有这个:
projects:
category1:
-
title: Project 1
desc: Description
etc...
-
title: Project 2
etc...
category2:
-
title: Project 3
desc: Description
etc...
-
title: Project 4
etc...
插件正在调用(它提供了 YAML 的 Ruby 哈希):
def...
YAML::load(File.read('projects.yml'))
end...
在模板中,我想:
{% for p in projects %}
...
这应该很简单,但它是一种令人痛苦的 Liquid 事物。
如何从插件中获取到 Liquid 的哈希值,以便在 {% for %} 循环中使用?
【问题讨论】: