-
|
Hey, it's me again, trying to figure all this thing out :) I tried to imitate several people (here for ex) that built a filter that uses localeCompare but it throws an error I can't manage to understand: eleventyConfig.addFilter('sortByTitle', values => {
return values.slice().sort((a, b) => a.data.title.localeCompare(b.data.title))
})Then I tried to do it another way, like @pdehaan suggested here, by using the default Sort() function fron Nunjuck but to no success as it returns an other error {% for note in taglist | sort(false, false, 'data.title') %}I guess there is something I don't understand about the way data is passed around but can't find anymore info to do what I'm trying to achieve. Here is the code from tags.njk: ---
layout: default
pagination:
data: collections
size: 1
alias: tag
permalink: /tags/{{ tag }}/
---
<h1>Étiquette: « {{ tag }} »</h1>
<ul>
{% set taglist = collections[ tag ] %}
{% for note in taglist | sortByTitle %}
<li><a href="{{ note.url }}">{{ note.data.title }}</a> {%if note.data.date %}<span class="small">| <time>{{ note.data.date | dateToLocalString }}</time></span>{% endif %}</li>
{% endfor %}
</ul> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 17 replies
-
|
Your logic here looks right to me: eleventyConfig.addFilter('sortByTitle', values => {
return values.slice().sort((a, b) => a.data.title.localeCompare(b.data.title))
})… but this error message seems to imply that one template might not have a
|
Beta Was this translation helpful? Give feedback.
Your logic here looks right to me:
… but this error message seems to imply that one template might not have a
titleattribute (it seems to beundefinedcausing an error trying to then readundefined.localeCompare()):