tpl/compare: Add cond (ternary) template func

Fixes #3860
This commit is contained in:
Bjørn Erik Pedersen
2017-09-08 14:16:21 +02:00
parent 202510fdc9
commit 0462c96a5a
3 changed files with 25 additions and 0 deletions

View File

@@ -142,6 +142,15 @@ func (n *Namespace) Lt(a, b interface{}) bool {
return left < right
}
// Conditional can be used as a ternary operator.
// It returns a if condition, else b.
func (n *Namespace) Conditional(condition bool, a, b interface{}) interface{} {
if condition {
return a
}
return b
}
func (*Namespace) compareGetFloat(a interface{}, b interface{}) (float64, float64) {
var left, right float64
var leftStr, rightStr *string