Previous and Next links and collections #3861
Replies: 1 comment
-
|
Not getting a response to my post, and needing to finish a project, I spend hours trying to figure this out, and I have posted the steps below: **** In eleventy-base-blog, the official starter package, I noticed blog.11tydata.js This file contains: export default { So I presume that it sets default values for all content files in the folder **** I copied blog.11tydata.js to the folder named "pages" containing the pages that I want to have previous / next links **** I renamed this file to pages.11tydata.js - I presume this file name needs to contain the name of the folder it is in **** I edited the file to suit export default { This assigns all pages the tag "pages" and to use the layout "page.njk" **** I created "layouts/page.njk" by copying it from "posts.njk" **** I edited page.njk and changed it to: {%- if collections.pages %}
**** This does show previous and next links for the content files in "pages" folder **** But this did not resolve the issue of the tag "Pages" as being shown as a taxonomy in each page But I noticed that {%- if tags %}
{%- for tag in tags | filterTagList %} {%- set tagUrl %}/tags/{{ tag | slugify }}/{% endset %} {%- endfor %} **** I found filterTagList in filter.js and edited it **** This now gives the desired result I would like to suggest that this is not a straightforward way to be able to add Previous and Next links to a set of pages in a folder. A feauture request would be to add a function / code where all content files in a folder can have Previous and Next links. Also would like to suggest that the docs which currently say: Take care to note that tags have a singular purpose in Eleventy: to construct collections of content. Some blogging platforms use Tags to refer to a hierarchy of labels for the content (e.g. a tag cloud). I am using the official "Eleventy Base Blog v9" and it does use tags not only for collections but also for a hierarchy of labels. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, noobie to 11ty, trying to understand things.
My understanding about Previous and Next links is that they are generated from collections:
https://www.11ty.dev/docs/filters/collection-items/
Eg:
And that a template becomes part of a collection by defining "tags", as per:
https://www.11ty.dev/docs/collections/
I am using the Eleventy Base Blog v9 starter and it does not seem to incorporate the above:
Eg
This starter has /content/blog/ with a number of sample blog templates and:
even though they do not contain "tags: post" in front matter, they do show up in the Previous and Next links. This seems to contradict the docs above. Also I have not been able to find anything that describes how to actually set a post to be part of a collection and hence Previous and Next links.
firstpost.md contains "tags: another tag" and this is used as a hierachical / taxonomy, and is not used to define it as part of a collection, even though https://www.11ty.dev/docs/filters/collection-items/ says "Take care to note that tags have a singular purpose in Eleventy: to construct collections of content. Some blogging platforms use Tags to refer to a hierarchy of labels for the content (e.g. a tag cloud)." So my experience here again directly contradicts what the docs say.
Also:
I have other questions regarding all this but I am so confused by this, I think I should wait to first understand the answers to the above issues.
Any help is much appreciated, thanks ahead of time.
Beta Was this translation helpful? Give feedback.
All reactions