-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Portfolio collection with next/ previous links but unique permalinks #426
Comments
I second this. I really need a way to get access to 'previous' and 'next' in a collection (of posts). e.g. (something like)
Interestingly enough, the code above shows the relevant data inside the collection items, but it does not seem to be accessible from inside templates. i.e. a collection item might show this structure, with
but attempting to access it inside the template, the values are
|
I suspect y’all want to follow along at #211 which seems to be a duplicate of this |
@zachleat I don't think this is exactly the same. The other seems to deal with pagination which (appears to be) deals with page numbering. e.g. /some-url/page/1 to /some-url/page/2 This thread is a different animal. Let's say the collection is ordered by some other sort. Not page number, but, say, date. It would be nice for the template to have access to the 'next' or 'previous' along some other scheme. |
@rendall I think the idea from @zachleat in #211 is this:
Here's my problem. I tried sticking my posts in a |
@thejohnfreeman You can set |
@chinchang I have tried that out (more here). Then the problem became that if I wanted to link to a post, I would need to manually craft the URL for that post's page in the pagination; I could no longer use the convention |
Hey people, how about using the Custom Collection feature to extend the posts themselves during the build? function addPrevNext(collectionArray) {
const l = collectionArray.length;
for (let p = 0; p < l; p++) {
if (p > 1)
collectionArray[p].data.previous = {
title: collectionArray[p - 1].data.title,
url: collectionArray[p - 1].url
};
if (p < l - 1)
collectionArray[p].data.next = {
title: collectionArray[p + 1].data.title,
url: collectionArray[p + 1].url
};
}
return collectionArray;
}
eleventyConfig.addCollection("my_posts",
collection => addPrevNext(collection.getFilteredByTag("posts"))
); I'm using this with my posts to generate collections of posts for a specific language and a specific category, and have previous/next post inside the collection: arrLocales = ["en", "fr"];
arrCategories = ["web", "citoyen", "papa"];
for (let i = 0; i < arrLocales.length; i++) {
let l = arrLocales[i];
eleventyConfig.addCollection(`posts_${l}`, collection =>
collection.getFilteredByTag("posts").filter(function(item) {
return item.data.locale == l;
})
);
for (let j = 0; j < arrCategories.length; j++) {
let c = arrCategories[j];
eleventyConfig.addCollection(`posts_${l}_${c}`, collection =>
addPrevNext(
collection.getFilteredByTag("posts").filter(function(item) {
return item.data.category == c && item.data.locale == l;
})
)
);
}
} |
Hey, awesome. I will try that, this weekend. |
Hi @borisschapira, the custom collection works well for this case, thank you. One note on your code example though. I think the index guard |
On re-read I believe this is a duplicate of #529 which has a nice workaround. Let’s coalesce over there. |
Hey, trying to put together a very basic portfolio site. Documentation is great regarding posts and single pages, but this kind of functionality is harder to suss out.. :/
Portfolio would be a pretty clear example case when documenting this.
Source:
Goal:
The text was updated successfully, but these errors were encountered: