mistakenot
mistakenot

Reputation: 614

How to group Jekyll pages by the first letter of the title?

I'm building a Jekyll site that has a page for each topic. I want to create an alphabetically grouped list of links to each page.

For example, if my topic titles are:

I want to end up with a list of links organised as:

So far, I have gotten code that looks like this:

{% assign topics_by_letter = 
    site.topics | group_by_expr: "topic", "topic.title | slice: 0, 1" %}

{% for letter in topics_by_letter %}
    <div>
        {{ letter.name }}
    </div>
{% endfor %}

site.topics is the correct name of the page collection and evaluates as expected.

All topics have a valid title label.

Where I am stuck is that letter.name evaluates to empty and I just have a list of empty divs. The snippet {{ page.title | slice: 0, 1 }} works and gives you back the first letter of the topic title.

What am I missing?

Upvotes: 2

Views: 253

Answers (1)

mistakenot
mistakenot

Reputation: 614

Was a typo, group_by_expr should be group_by_exp.

Upvotes: 1

Related Questions