How can I conditionally display something else if my range is empty?
{{range .Users}}
...
{{end}}
If the range is empty, I want to display a different block of HTML.
Use {{range pipeline}} T1 {{else}} T0 {{end}}
:
{{range pipeline}} T1 {{else}} T0 {{end}} The value of the pipeline must be an array, slice, map, or channel. If the value of the pipeline has length zero, dot is unaffected and T0 is executed; otherwise, dot is set to the successive elements of the array, slice, or map and T1 is executed.
Example:
{{range .Users}}
...
{{else}}
<p>No users</p>
{{end}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With