Document Pages support in union and intersect

Fixes #26
This commit is contained in:
Bjørn Erik Pedersen 2017-07-17 11:11:10 +02:00
parent 14beb0ec67
commit b1238c98a1
2 changed files with 26 additions and 0 deletions

View File

@ -41,5 +41,18 @@ The following is an example of a "related posts" [partial template][partials] th
``` ```
{{% /code %}} {{% /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/ [partials]: /templates/partials/
[single]: /templates/single-page-templates/ [single]: /templates/single-page-templates/

View File

@ -34,3 +34,16 @@ Given two arrays (or slices) A and B, this function will return a new array that
{{ union nil nil }} {{ union nil nil }}
<!-- returns an error because both arrays/slices have to be of the same type --> <!-- returns an error because both arrays/slices have to be of the same type -->
``` ```
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`.