summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-11-17 12:29:26 -0500
committerGitHub <noreply@github.com>2018-11-17 12:29:26 -0500
commit0cf7734ef776cc7701dfbb08b080cecf5066f0eb (patch)
tree5a04e4f0204d29c312e45cce0321eeb00ff10f7b /docs
parent3dad8fefa1dccc15c9d0bcba3219305c3cbab69c (diff)
parent45b527a6237e758faa022b9e5f9b02a806ea9b2e (diff)
Merge pull request #434 from hairyhenderson/ternary-func-428
New test.Ternary function
Diffstat (limited to 'docs')
-rw-r--r--docs/content/functions/test.md40
1 files changed, 40 insertions, 0 deletions
diff --git a/docs/content/functions/test.md b/docs/content/functions/test.md
index c6d24008..dfb0b0ae 100644
--- a/docs/content/functions/test.md
+++ b/docs/content/functions/test.md
@@ -122,3 +122,43 @@ template: <arg>:1:25: executing "<arg>" at <required "The `confi...>: error call
$ gomplate -d config=config.yaml -i '{{ (ds "config").bogus | required "The `config` datasource must have a value defined for `bogus`" }}'
template: <arg>:1:7: executing "<arg>" at <"config">: map has no entry for key "bogus"
```
+
+## `test.Ternary`
+
+**Alias:** `ternary`
+
+Returns one of two values depending on whether the third is true. Note that the third value does not have to be a boolean - it is converted first by the [`conv.ToBool`](../conv/#conv-tobool) function (values like `true`, `1`, `"true"`, `"Yes"`, etc... are considered true).
+
+This is effectively a short-form of the following template:
+
+```
+{{ if conv.ToBool $condition }}{{ $truevalue }}{{ else }}{{ $falsevalue }}{{ end }}
+```
+
+Keep in mind that using an explicit `if`/`else` block is often easier to understand than ternary expressions!
+
+### Usage
+```go
+test.Ternary truevalue falsevalue condition
+```
+
+```go
+condition | test.Ternary truevalue falsevalue
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `truevalue` | _(required)_ the value to return if `condition` is true |
+| `falsevalue` | _(required)_ the value to return if `condition` is false |
+| `condition` | _(required)_ the value to evaluate for truthiness |
+
+### Examples
+
+```console
+$ gomplate -i '{{ ternary "FOO" "BAR" false }}'
+BAR
+$ gomplate -i '{{ ternary "FOO" "BAR" "yes" }}'
+FOO
+```