From 41df916594e99c6217ef98c13ff8f1942249c184 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Wed, 14 Aug 2024 09:02:28 -0700 Subject: [PATCH] Document the 'else with' construct introduced with Go 1.23 --- content/en/contribute/development.md | 2 +- content/en/functions/go-template/if.md | 2 +- content/en/functions/go-template/with.md | 14 ++++++++++++++ content/en/templates/introduction.md | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/content/en/contribute/development.md b/content/en/contribute/development.md index f6ff44ced..e4b183e93 100644 --- a/content/en/contribute/development.md +++ b/content/en/contribute/development.md @@ -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] diff --git a/content/en/functions/go-template/if.md b/content/en/functions/go-template/if.md index 19c887f25..9fdf80e99 100644 --- a/content/en/functions/go-template/if.md +++ b/content/en/functions/go-template/if.md @@ -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 }} diff --git a/content/en/functions/go-template/with.md b/content/en/functions/go-template/with.md index 3a73d54bb..3d628e28d 100644 --- a/content/en/functions/go-template/with.md +++ b/content/en/functions/go-template/with.md @@ -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 diff --git a/content/en/templates/introduction.md b/content/en/templates/introduction.md index bb8702717..0a3ff2b0f 100644 --- a/content/en/templates/introduction.md +++ b/content/en/templates/introduction.md @@ -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.