Skip to content

Commit

Permalink
Document the 'else with' construct introduced with Go 1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Aug 14, 2024
1 parent 2f793d3 commit 57aecb6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/en/contribute/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion content/en/functions/go-template/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 14 additions & 0 deletions content/en/functions/go-template/with.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions content/en/templates/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 57aecb6

Please sign in to comment.