-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Add support for pages in the union/intersect template function #3174
Comments
Note that instead of adding support for one and one type, it should support any type that can be compared by And I think you switched AND and OR in the bullet points above. |
Makes sense
The typical copy-and-paste dilemma. It's fixed now. |
@moorereason @digitalcraftsman The intersect func should be fine now, right? It would be cool if we could also get the union up to speed? That would give us a good story on page queries. |
Great! We should also add some nice examples to the docs. We should link from the docs for the /cc @rdwatters |
@digitalcraftsman my post was riddled with question marks, which may be good to address before we start worrying about examples. |
The I still don't think we support Page comparisons. We are doing comparisons of basic types. We don't compare structs. I looked at comparing Pages a few days ago and ran into an issue with cyclical imports since |
@moorereason re the cyclic, I had a Git stash laying around, pushed it in #3484 -- I probably will not complete this, so take what you want ... You don't really need to test real pages, just make up some structs and slices of struct pointers. |
This enables `AND` (`intersect`) and `OR` (`union`) filters when combined with `where`. Example: ```go {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }} {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }} {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }} ``` The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page params. Fixes gohugoio#3174
This enables `AND` (`intersect`) and `OR` (`union`) filters when combined with `where`. Example: ```go {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }} {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }} {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }} ``` The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page params. Fixes #3174
If there two range, for example: Oh, I find it |
Complex
where
-nestings could be simplified by filtering pages withunion
andintersect
:union
corresponds to the logical OR operator (x is an element of set A OR set B)intersect
corresponds to the logical AND operator (x is an element of set A AND set B)Example: find all pages where
.Params.a
equals"v1"
AND.Params.b
equals"v2"
The text was updated successfully, but these errors were encountered: