hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

intersect.md (1076B)

    1 ---
    2 title: intersect
    3 linktitle: intersect
    4 description: Returns the common elements of two arrays or slices, in the same order as the first array.
    5 date: 2017-02-01
    6 publishdate: 2017-02-01
    7 lastmod: 2017-02-01
    8 categories: [functions]
    9 menu:
   10   docs:
   11     parent: "functions"
   12 keywords: [collections,intersect,union,complement,symdiff]
   13 signature: ["intersect SET1 SET2"]
   14 workson: []
   15 hugoversion:
   16 relatedfuncs: []
   17 deprecated: false
   18 aliases: []
   19 ---
   20 An useful example is to use it as `AND` filters when combined with where:
   21 
   22 ## AND filter in where query
   23 
   24 ```
   25 {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
   26 {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
   27 {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
   28 ```
   29 
   30 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.
   31 
   32 See [union](/functions/union) for `OR`.
   33 
   34 
   35 [partials]: /templates/partials/
   36 [single]: /templates/single-page-templates/