-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prev/Next for items in eleventyNavigation items #22
Comments
I also ran into this, so I added a filter to flatten the navigation hierarchy, and add /**
* Flatten a navigation object into an array, and add "next" and "prev"
* properties.
*/
eleventyConfig.addFilter('flattenNavigationAndAddNextPrev', (nav) => {
const flat = [];
const visit = (items) => {
for (const item of items) {
flat.push(item);
visit(item.children);
}
};
visit(nav);
for (let i = 0; i < flat.length; i++) {
const item = flat[i];
item.prev = flat[i - 1];
item.next = flat[i + 1];
}
return flat;
}); Then in my template I did something like this:
Hope that helps. |
Wow, that's cool. Thank you very much for sharing your solution. It has been a while so i don't remember what i did but this would be super helpful for my future project 😃. Thank you |
This worked like a charm when I edited the code like below, in template: - {% set flatNavItems = collections.docs | eleventyNavigation | flattenNavigationAndAddNextPrev %}
+ {% set flatNavItems = collections.all | eleventyNavigation | flattenNavigationAndAddNextPrev %} |
Hi, thank you for a very useful plugin. I was wondering of something like Prev/Next button is possible for items that prepared by eleventyNavigation?
Some think like:
Right now, if I have nested navigation, the Prev/Next code in this section but as you might have guess, the items would not be in the same order.
Thank you very much
The text was updated successfully, but these errors were encountered: