Skip to content

text/template: missingkey=zero behaves different from html/template #70681

@lirtistan

Description

@lirtistan

Go version

go version go1.23.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/enrico/.cache/go-build'
GOENV='/home/enrico/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE='ebony.local'
GOMODCACHE='/home/enrico/.asdf/installs/golang/1.23.4/packages/pkg/mod'
GONOPROXY='ebony.local'
GONOSUMDB='ebony.local'
GOOS='linux'
GOPATH='/home/enrico/.asdf/installs/golang/1.23.4/packages'
GOPRIVATE='ebony.local'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/enrico/.asdf/installs/golang/1.23.4/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/enrico/.asdf/installs/golang/1.23.4/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/enrico/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/enrico/Projects/golang/active/web/chi-client/go.mod'
GOWORK='/home/enrico/Projects/golang/active/web/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1859946843=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Parsing a template with help of text/template, but the missingkey=zero option behaves different from html/template.

A missing key in map[string]any is printed as <no value> which is different from what i expect if i render the template with .Option("missingkey=zero").

html/template behaves correct.

See https://github.com/lirtistan/template_bug for a working example.

What did you see happen?

With text/template i get the following result...

<div class="vstack">
    <p>Foo</p>
    <no value>
</div>

with html/template i get the correct result...

<div class="vstack">
    <p>Foo</p>

</div>

also see attached screenshots...

here with text/template...
image

here with html/template...
image

What did you expect to see?

An output without , like that html example below

<div class="hstack">
    <p>Foo</p>

</div>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions