collections.Intersect
Returns a slice containing the common elements found in two given slices, in the same order as the first slice.
- Syntax
- collections.Intersect SLICE1 SLICE2
- Returns
- []any
- Alias
- intersect
Usage
The collections.Intersect function returns a slice containing the common elements found in two given slices, in the same order as the first slice. The returned slice does not contain duplicate elements.
Use this function with the collections.Where function to combine filters with a logical AND. To combine filters with a logical OR, use the collections.Union function.
Examples
{{ collections.Intersect (slice 1 2 3 4) (slice 4 3 5) }} → [3 4]Returning regular pages that have a content type other than page or about, or that are pinned, and that have an images parameter:
{{ $pages := where site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages = $pages | union (where site.RegularPages "Params.pinned" true) }}
{{ $pages = $pages | collections.Intersect (where site.RegularPages "Params.images" "!=" nil) }}Last updated:
November 24, 2026
:
content: Apply style guide to collections functions (04f2e2939)
Improve this page