From b1238c98a1d4ac6f72e6651fc8d4c40d69452f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 17 Jul 2017 11:11:10 +0200 Subject: [PATCH] Document Pages support in union and intersect Fixes #26 --- content/functions/intersect.md | 13 +++++++++++++ content/functions/union.md | 13 +++++++++++++ 2 files changed, 26 insertions(+) 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`.