Jekyll Liquid 模板:在页面中使用布局变量
Jekyll Liquid Template: Use Variable of Layout in Page
我有以下文件:
_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
访问变量,但它不起作用。
如何访问变量?
您可以将该变量放在布局和帖子之外,然后 include 它在您需要的地方:
在 _includes/customdata.html
中创建一个 include:
{% assign col = site.interfaceServer | where:"neededTopCollectionItem", page.topCollectionItem | sort: "order" %}
然后将其包含在someFile.md
中:
{%include customdata.html %}
{{col}}
或在布局中。
我有以下文件:
_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
访问变量,但它不起作用。
如何访问变量?
您可以将该变量放在布局和帖子之外,然后 include 它在您需要的地方:
在 _includes/customdata.html
中创建一个 include:
{% assign col = site.interfaceServer | where:"neededTopCollectionItem", page.topCollectionItem | sort: "order" %}
然后将其包含在someFile.md
中:
{%include customdata.html %}
{{col}}
或在布局中。