The header of my Jekyll page looks something like this
---
title: Some title here
FY: 2021
---
I would like to use the FY
metadata in a Liquid filter like this:
{% assign reports = site.Collection | where:"FY", "{{ page.FY }}" %}
<ul>
{% for report in reports %}
<li><a href="{{ report.url }}">{{ report.date | date: "%Y-%m-%d" }}</a> {{ report.title }}</li>
{% endfor %}
</ul>
When I do this, the filter excludes everything. When I use the value explicitly (like below) then I get the list of reports as expected.
{% assign reports = site.Collection | where:"FY", 2022 %}
1 Like
Inside of Liquid tags (delimited by {% %}
), variable expressions can be used directly, without the object delimiters ({{ }}
). So this should work (untested code):
{% assign reports = site.Collection | where:"FY", page.FY %}
1 Like
@chuckhoupt That’s exactly it. Thanks for helping out a rookie!
However, there’s a deviation to this expectation.
Jekyll core’s builtin {% include .. %}
and perhaps {% link .. %}
tag (not sure) breaks the expectation.
{% assign file = "header.html" %}
{% include {{ file }} %}
1 Like
Yes indeed include
can reference a variable using an expression like that
But link
evaluates its input literally as text in a way that doesn’t support the expression