diff options
author | rogeryk <rogeryk@outlook.com> | 2023-11-28 20:41:03 +0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-02-24 21:59:12 +0000 |
commit | 08d9397170e5870b72a95233e8e4ec43d2d70e30 (patch) | |
tree | 766a6afaf628dcaa79587eb6d0f7074eeebc7e9b /src/html | |
parent | e0fc269f77af97f7cf33097d82f92ff7e08a2f06 (diff) | |
download | go-08d9397170e5870b72a95233e8e4ec43d2d70e30.tar.gz go-08d9397170e5870b72a95233e8e4ec43d2d70e30.zip |
text/template: add "else with" action
Add "else with" action will reduce the template complexity in some use cases(#57646).
This action will be added:
{{with pipeline}} T1 {{else with pipeline}} T0 {{end}}.
Fixes #57646
Change-Id: I90ed546ab671805f753343b00bd3c9d1a1d5581d
Reviewed-on: https://go-review.googlesource.com/c/go/+/545376
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/template/exec_test.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/html/template/exec_test.go b/src/html/template/exec_test.go index 05302156e0..f60308e679 100644 --- a/src/html/template/exec_test.go +++ b/src/html/template/exec_test.go @@ -561,6 +561,8 @@ var execTests = []execTest{ {"with $x struct.U.V", "{{with $x := $}}{{$x.U.V}}{{end}}", "v", tVal, true}, {"with variable and action", "{{with $x := $}}{{$y := $.U.V}}{{$y}}{{end}}", "v", tVal, true}, {"with on typed nil interface value", "{{with .NonEmptyInterfaceTypedNil}}TRUE{{ end }}", "", tVal, true}, + {"with else with", "{{with 0}}{{.}}{{else with true}}{{.}}{{end}}", "true", tVal, true}, + {"with else with chain", "{{with 0}}{{.}}{{else with false}}{{.}}{{else with `notempty`}}{{.}}{{end}}", "notempty", tVal, true}, // Range. {"range []int", "{{range .SI}}-{{.}}-{{end}}", "-3--4--5-", tVal, true}, |