【问题标题】:Jekyll Liquid Template: Use Variable of Layout in PageJekyll Liquid 模板:在页面中使用布局变量
【发布时间】:2017-06-27 14:10:59
【问题描述】:

我有以下文件:

_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 访问该变量,但它不起作用。

如何访问变量?

【问题讨论】:

    标签: html variables jekyll liquid


    【解决方案1】:

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

    _includes/customdata.html中创建一个include

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

    然后将其包含在someFile.md

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

    或在布局中

    【讨论】:

      猜你喜欢
      • 2013-07-24
      • 1970-01-01
      • 2012-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      相关资源
      最近更新 更多