Document the 'else with' construct introduced with Go 1.23

This commit is contained in:
Joe Mooring
2024-08-14 09:02:28 -07:00
committed by Bjørn Erik Pedersen
parent 9c4697ab32
commit 41df916594
4 changed files with 30 additions and 2 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ For a complete guide to contributing to Hugo, see the [Contribution Guide].
To build the extended edition of Hugo from source you must:
1. Install [Git]
1. Install [Go] version 1.20 or later
1. Install [Go] version 1.23.0 or later
1. Install a C compiler, either [GCC] or [Clang]
1. Update your `PATH` environment variable as described in the [Go documentation]
+1 -1
View File
@@ -34,7 +34,7 @@ Use with the [`else`] statement:
{{ end }}
```
Use `else if` to check multiple conditions.
Use `else if` to check multiple conditions:
```go-html-template
{{ $var := 12 }}
+14
View File
@@ -36,6 +36,20 @@ Use with the [`else`] statement:
{{ end }}
```
Use `else with` to check multiple conditions:
```go-html-template
{{ $v1 := 0 }}
{{ $v2 := 42 }}
{{ with $v1 }}
{{ . }}
{{ else with $v2 }}
{{ . }} → 42
{{ else }}
{{ print "v1 and v2 are falsy" }}
{{ end }}
```
Initialize a variable, scoped to the current block:
```go-html-template
+14
View File
@@ -509,6 +509,20 @@ See documentation for [`with`], [`else`], and [`end`].
{{ end }}
```
To test multiple conditions:
```go-html-template
{{ $v1 := 0 }}
{{ $v2 := 42 }}
{{ with $v1 }}
{{ . }}
{{ else with $v2 }}
{{ . }} → 42
{{ else }}
{{ print "v1 and v2 are falsy" }}
{{ end }}
```
### Access site parameters
See documentation for the [`Params`](/methods/site/params/) method on a `Site` object.