From 0c3c04fd63a7f140bdca0d3ca9b1e9dc794ebd77 Mon Sep 17 00:00:00 2001 From: Bradley Nelson Date: Sat, 25 May 2019 01:19:43 -0600 Subject: [PATCH] Merge pull request #827 from BCNelson/range-patch Range patch --- content/en/templates/introduction.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/content/en/templates/introduction.md b/content/en/templates/introduction.md index e07957656..02a580e79 100644 --- a/content/en/templates/introduction.md +++ b/content/en/templates/introduction.md @@ -233,6 +233,18 @@ key. {{ end }} ``` +#### Example 5: Conditional on empty _map_, _array_, or _slice_. + +If the _map_, _array_, or _slice_ passed into the range is zero-length then the else statment is evaluated. + +```go-html-template +{{ range $array }} + {{ . }} +{{else}} + +{{ end }} +``` + ### Conditionals `if`, `else`, `with`, `or`, and `and` provide the framework for handling conditional logic in Go Templates. Like `range`, each statement is closed with an `{{ end }}`.