11ty/eleventy-navigation

Paginated eleventyComputed eleventyNavigation

enly1 opened this issue · 3 comments

enly1 commented

I'm trying to get a paginated global dataset to add items for use with the navigation plugin, but only the first item in the paginated set gets added.

The following is the navigation dump once 10 items have been paginated:

Snippet from layouts/main.njk:

    {% set navPages = collections.all | eleventyNavigation %}
    {{ navPages | dump }} 

Generates:

[{"key":"Jackie Chan","title":"Jackie Chan","url":"/influencer/jackie-chan/","pluginType":"eleventy-navigation","children":[{"key":"JC-SKU1","title":"JC-SKU1","parent":"Jackie Chan","url":"/influencer/jackie-chan/jc-sku1/","pluginType":"eleventy-navigation","parentKey":"Jackie Chan","children":[]}]}]

Only 1 item appears for each of the paginated sets. In this case influencers and influencer products paginated sets.

Example from the influencer products frontmatter:

---
layout: layouts/main.njk
pagination:
    data: influencer_products
    size: 1
    alias: product
permalink: /influencer/{{product.channel | slug }}/{{ product.id | slug}}/
eleventyComputed:
    eleventyNavigation:
        key: "{{product.id}}"
        title: "{{product.id}}"
        parent: "{{product.channel}}"
    title: "Product: {{product.channel}}"
---

I have also tried doing this without using frontmatter and injecting eleventyComputed output from js and that results in the same output.

Can navigation be used in this way with pagination ?

I had a similar problem, and after some digging found this in the docs. Modifying your frontmatter like this should help:

pagination:
    data: influencer_products
    size: 1
    alias: product
    addAllPagesToCollections: true
enly1 commented

Thanks - that worked a treat.

I had looked at that page earlier for something else, so light-bulb moment reading your reply.

Amusingly, I wasn't aware of the link to collections for navigation until I went back and looked. Joys of too much copy/paste coding that has been going on this week.

Fairly obvious now looking at the {% set navPages = collections.all | eleventyNavigation %}

Wish I could give 100 stars to this, thanks!