elotroalex
elotroalex

Reputation: 59

Pass include parameter to select folder from collections in Jekyll

I'm building an academic journal on Jekyll 3.0.3 with periodical issues. Right now I'm trying to build an automatically constructed Table of Contents that all issues can share, using includes to add it, and ordering the pages through a value in an 'order' value in YAML header. I'm using collections to separate the issues. For example, the first issue is housed in a folder called _issue01.

Second issue in _issue02, etc. I'm trying to pass in a parameter from the places I include it using the syntax:

{% include toc.html foo=site.issue01 %}

And then on the toc.html receive the foo using:

{% assign documents = {{include.foo}} | sort: 'order' %}

The filter is complaining:

Error: Liquid error (line 13): Cannot sort a null object.

I tried another approach taking the cue from this thread.

{% capture foo %}{{ site.issue01 }}{% endcapture %}
{% include foo.html %}

But that seems to pass the whole thing as a string:

Error: undefined method `sort' for #

Upvotes: 3

Views: 636

Answers (1)

elotroalex
elotroalex

Reputation: 59

I found the answer:

In the file where you want to include the toc:

{% include toc.html bar=site.issue01 %}

And in the toc.html the trick is to use parentheses:

{% assign documents = (include.bar | sort: 'order') %}

Upvotes: 1

Related Questions