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 }}`.