Merge pull request #827 from BCNelson/range-patch

Range patch
This commit is contained in:
Bradley Nelson 2019-05-25 01:19:43 -06:00 committed by Bjørn Erik Pedersen
parent b14dd35053
commit 0c3c04fd63

View File

@ -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}}
<!-- This is only evaluated if $array is empty -->
{{ 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 }}`.