HUGO
Menu
GitHub 87548 stars Mastodon

or

Returns the first truthy argument. If all arguments are falsy, returns the last argument.

Syntax

or VALUE...

Returns

any

假值包括 false0、任何 nil 指针或接口值、任何长度为零的数组、切片、映射或字符串,以及零值 time.Time

其他所有值都是真值。

The or function evaluates the arguments from left to right, and returns when the result is determined.

{{ or 0 1 2 }} → 1 (int)
{{ or false "a" 1 }} → a (string)
{{ or 0 true "a" }} → true (bool)

{{ or false "" 0 }} → 0 (int)
{{ or 0 "" false }} → false (bool)

{{ or true (math.Div 1 0) }} → true (bool)

有关更多信息,请参阅 Go 的 text/template 文档。


Last updated: January 1, 0001
Improve this page