github.com/jbramsden/hugo@v0.47.1/docs/content/en/functions/union.md (about)

     1  ---
     2  title: union
     3  # linktitle: union
     4  description: Given two arrays or slices, returns a new array that contains the elements or objects that belong to either or both arrays/slices.
     5  godocref:
     6  date: 2017-02-01
     7  publishdate: 2017-02-01
     8  lastmod: 2017-03-12
     9  categories: [functions]
    10  menu:
    11    docs:
    12      parent: "functions"
    13  keywords: [filtering,lists]
    14  signature: ["union SET1 SET2"]
    15  workson: []
    16  hugoversion: 0.20
    17  relatedfuncs: [intersect,where]
    18  deprecated: false
    19  aliases: []
    20  ---
    21  
    22  Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both. The elements supported are strings, integers, and floats (only float64).
    23  
    24  ```
    25  {{ union (slice 1 2 3) (slice 3 4 5) }}
    26  <!-- returns [1 2 3 4 5] -->
    27  
    28  {{ union (slice 1 2 3) nil }}
    29  <!-- returns [1 2 3] -->
    30  
    31  {{ union nil (slice 1 2 3) }}
    32  <!-- returns [1 2 3] -->
    33  
    34  {{ union nil nil }}
    35  <!-- returns an error because both arrays/slices have to be of the same type -->
    36  ```
    37  
    38  
    39  This is also very useful to use as `OR` filters when combined with where:
    40  
    41  ```
    42  {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
    43  {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
    44  {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
    45  ```
    46  
    47  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.
    48  
    49  See [intersect](/functions/intersect) for `AND`.