Context
I have a local jekyll instance to manage my poetry, instead of dealing with a WYSIWYG editor. The poems are technically a separate jekyll project that I symlink to other jekyll projects (a submission manager, a personal website, my first book). I specify _poems
as a Collection in each config file.
Goal
I’m trying to specify pages from the _poems
collection to access in a new page. But I can’t figure out how to get jekyll to access the collection programmatically. I can hardcode the paths with an assign
+ for
loop, but this is tedious & error-prone.
Details
I want to specify the file names from the _poems
collection so that I can loop through them in a file like this:
---
author: "marmalamuc"
title: "Submission example"
date: 2025-06-29
layout: default
permalink: example.html
poems:
- poem1.html
- poem2.html
- poem3.html
---
<p>{% include contactInfo.md %}</p>
<p id="journal">{{ page.title }}<br>
{{ page.date | date: "%d %b %Y" }}</p>
<h2>Contents</h2>
<ul>
{% for item in page.poems %}
<li><a href="#poem{% increment counter1 %}">{{item.title}}</a></li>
{% endfor %}
</ul>
{% for item in page.poems %}
<div class="page-break" id="poem{% increment counter2 %}">
<h3>{{ item.title }}</h3>
{% if item.epigraph %}<p class="epigraph">{{item.epigraph}}</p>{% endif %}
{{ item.content }}
{% if item.dedication %}<p class="dedication">{{item.dedication}}</p>{% endif %}
</div>
{% endfor %}
But I can’t figure out how to get jekyll to access the poems. The output is always blank (though it recognizes the correct number of items in the ul
& page breaks). I’ve tried all kinds of things with assign
, capture
, cycle
, but can’t get it to work if I specify the files as a group. For example, this (& several variations) does not work:
{% for poem in page.poems %}
{% assign p = site.poems | where: "permalink", "{{poem}}" %}
<div class="page-break" id="poem{% increment var %}">
<h3>{{ p.title }}</h3>
{% if p.epigraph %}<p class="epigraph">{{p.epigraph}}</p>{% endif %}
{{ p.content }}
{% if p.dedication %}<p class="dedication">{{p.dedication}}</p>{% endif %}
</div>
{% endfor %}
Everything does work if I hardcode a variable for each file (my current approach), or based on a frontmatter property in the poems, then loop through to grab the title & content; i.e.:
{% assign p1 = site.poems | where: "permalink", "poem1.html" %}
{% assign ode = site.poems | where: "series", "ode" %}
But the former is the tedious approach I’m trying to get away from, and the latter is not useful for creating submissions.
This is so simple in theory, but I’ve been banging my head against a wall for months trying to get it right.
Any ideas?