mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'
This commit is contained in:
@@ -1,26 +1,18 @@
|
||||
---
|
||||
title: union
|
||||
# linktitle: union
|
||||
description: Given two arrays or slices, returns a new array that contains the elements or objects that belong to either or both arrays/slices.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-03-12
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
parent: functions
|
||||
keywords: [collections,intersect,union,complement]
|
||||
signature: ["union SET1 SET2"]
|
||||
workson: []
|
||||
hugoversion: 0.20
|
||||
relatedfuncs: [intersect,where]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
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).
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ union (slice 1 2 3) (slice 3 4 5) }}
|
||||
<!-- returns [1 2 3 4 5] -->
|
||||
|
||||
@@ -38,7 +30,7 @@ Given two arrays (or slices) A and B, this function will return a new array that
|
||||
|
||||
This is also very useful to use as `OR` filters when combined with where:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ $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) }}
|
||||
|
Reference in New Issue
Block a user