compare.Eq
Reports whether the first argument is equal to any of the subsequent arguments.
- Syntax
- compare.Eq ARG1 ARG2 [ARG...]
- Returns
- bool
- Alias
- eq
Usage
The compare.Eq function reports whether the first argument is equal to any of the subsequent arguments. Numbers are compared by value, regardless of type. You can also use this function to compare strings, boolean values, dates, and other comparable data types.
time.Time values are compared by the moment they represent, regardless of time zone. To compare date strings, such as custom date parameters in front matter, convert them with the time.AsTime function first.
Examples
{{ compare.Eq 1 1 }} β true
{{ compare.Eq 1 2 }} β false
{{ compare.Eq 1 1 1 }} β true
{{ compare.Eq 1 1 2 }} β true
{{ compare.Eq 1 2 1 }} β true
{{ compare.Eq 1 2 2 }} β falseComparing numbers of different types:
{{ compare.Eq 1 1.0 }} β trueComparing other data types:
{{ compare.Eq "ab" "a" }} β false
{{ compare.Eq now (time "1964-12-30") }} β false
{{ compare.Eq true false }} β falseComparing the same moment in different time zones:
{{ $utc := time.AsTime "2023-07-19T17:42:36Z" }}
{{ $tokyo := $utc | time.In "Asia/Tokyo" }}
{{ compare.Eq $utc $tokyo }} β true