Skip to content
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

Is it possible to filter all collections at once? #823

Open
nhoizey opened this issue Dec 13, 2019 · 5 comments
Open

Is it possible to filter all collections at once? #823

nhoizey opened this issue Dec 13, 2019 · 5 comments

Comments

@nhoizey
Copy link
Contributor

nhoizey commented Dec 13, 2019

I'm using Forestry to edit content for a site generated with Eleventy, and it manages drafts with a YFM variable named published with values false and true.

I would like to filter out all drafts, but it currently requires defining all collections one after the other in .eleventy.js and filter out the items that have published: false:
nhoizey/precious-prana.com@19d20ec

Every time I had a collection, I will have to remember adding this.

Is there a simpler way?

@danfascia
Copy link

danfascia commented Jan 4, 2020

Use this gist to filter the array by key:value pair at the point of setting the collection in the template language. Tested to work with nunjucks and liquid.

https://gist.github.com/danfascia/e15b8e900a767c1b9677d1cbc74cc51c

@nhoizey
Copy link
Contributor Author

nhoizey commented Jan 12, 2020

@danfascia sorry, I don't understand how to use it, could you link to an usage example? thanks

@DirtyF
Copy link
Contributor

DirtyF commented Jan 12, 2020

@nhoizey This filter is used by @paulrobertlloyd to select elements from a collection

Maybe not quiet what you're looking for, as you don't wan't those elements listed in your collection at all if I understand. You might want to filter drafts in the collection like @rem does. It's quiet similar to what you do.

From what I understand, you want to make it a function you could use in all your collections?

@paulrobertlloyd
Copy link
Contributor

As an aside, if you are using Liquid for templating, it’s builtin where filter would achieve the same as my custom filter. However 11ty depends on an earlier version of LiquidJS, which doesn’t support this feature.

@nhoizey
Copy link
Contributor Author

nhoizey commented Jan 13, 2020

@paulrobertlloyd I'm using Nunjucks… 😅

@DirtyF I would like to filter draft content out of all collections without having to define collections in .eleventy.js at all, so it looks like that's not what @Rem does.

Maybe @danfascia's solution but inverted (doesnt_contain instead of contains) would be a way, pretty similar to @paulrobertlloyd 's where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants