Jekyll液体模板:在页面中使用布局变量

时间:2017-06-27 14:11:00

标签: html variables jekyll liquid

我有以下文件:

_layouts / twoPointLayout.html

---
layout: documentationLayout
---
{% assign col = site.interfaceServer | where:"neededTopCollectionItem", page.topCollectionItem | sort: "order" %}

<ol class="breadcrumb">
  <li><a href="{{ col[0].url }}">{{ col[0].title }}</a></li>
  <li class="active">{{ page.title }}</li>
</ol>

<h3>{{ col[0].order }}.{{ page.order }} {{ page.title }}</h3>
{{ content }}

someFile.md

---
title: "Some title"
identifier: hints
order: 3
orderPagination: 24
layout: twoPointLayout
topCollectionItem: xyz
neededTopCollectionItem: xyz_hints
---
{% assign items = site.interfaceServer | where:"topCollectionItem", "xdt-documentation_hints" | sort: "order" %}
{{ page.col[0].order }} // This doesn`t work

{% for item in items %}
  <h4 id="{{ item.identifier }}"><a href="{{ item.url }}">{{ col[0].order }}.{{ page.order }}.{{ item.order }} {{ item.title }}</a></h4>
{% endfor %}

在布局twoPointLayout.html中有一个col的变量声明。现在,我需要在页面someFile.md中使用与此内容相同的变量。

我使用page.col[0].order来访问变量,但它不起作用。

如何访问变量?

1 个答案:

答案 0 :(得分:2)

您可以将该变量放在布局和帖子之外,然后include将其放在您需要的位置:

_includes/customdata.html中创建 include

{% assign col = site.interfaceServer | where:"neededTopCollectionItem", page.topCollectionItem | sort: "order" %}

然后将其包含在someFile.md

{%include customdata.html %}
{{col}}

布局