HUGO
Menu
GitHub 90498 stars Mastodon

collections.In

Reports whether a value exists within the given slice or string.
Syntax
collections.In SLICE|STRING VALUE
Returns
bool
Alias
in
{{ $s := slice "a" "b" "c" }}
{{ in $s "b" }} → true
{{ $s := "abc" }}
{{ in $s "b" }} → true

The function compares time.Time values by the moment they represent, regardless of time zone:

{{ $utc := time.AsTime "2023-07-19T17:42:36Z" }}
{{ $tokyo := $utc | time.In "Asia/Tokyo" }}
{{ in (slice $utc) $tokyo }} → true