diff --git a/content/functions/intersect.md b/content/functions/intersect.md index 5c1ffce97..fc56e9b93 100644 --- a/content/functions/intersect.md +++ b/content/functions/intersect.md @@ -41,5 +41,18 @@ The following is an example of a "related posts" [partial template][partials] th ``` {{% /code %}} +This is also very useful to use as `AND` filters when combined with where: + +```html +{{ $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. + +See [union](/functions/union) for `OR`. + + [partials]: /templates/partials/ [single]: /templates/single-page-templates/ diff --git a/content/functions/union.md b/content/functions/union.md index 8938a3728..7baf90592 100644 --- a/content/functions/union.md +++ b/content/functions/union.md @@ -34,3 +34,16 @@ Given two arrays (or slices) A and B, this function will return a new array that {{ union nil nil }} ``` + + +This is also very useful to use as `AND` filters when combined with where: + +```html +{{ $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. + +See [intersect](/functions/intersect) for `AND`.