Lars
Lars

Reputation: 173

Jekyll Liquid Template: Use Variable of Layout in Page

i have the following files:

_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 %}

In the Layout twoPointLayout.html there is a variable declaration of col. Now i need to use this Variable with the same content in the page someFile.md.

I have used page.col[0].order to access the variable, but it doesn`t work.

How can I access the variable?

Upvotes: 1

Views: 939

Answers (1)

marcanuy
marcanuy

Reputation: 23982

You can put that variable outside the layout and posts, and then include it where you need it:

Create an include in _includes/customdata.html:

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

Then include it in someFile.md:

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

or in the layout.

Upvotes: 3

Related Questions