I'm using Go 1.19 with the built-in HTML template engine. Is there a way to test if a block is defined in a particular template file?
Specifically, I want to implement optional header entries in the Go HTML template.
I have a general layout template that includes a content template when rendered.
I want to implement as below...
Currently, the <meta name="description" content="{{block "description" .}}{{end}}"> result in an empty description tag. I'd like to not have the tag at all if there is nothing in it.
Any ideas?
layout.gohtml (simplified)[updated]
<html>
<head>
<title>{{block "title" .}}The Title{{end}}</title>
{{if .renderDescription}}
<meta name="description" content="{{template "description"}}">
{{end}
</head>
<body>
<header></header>
{{template "content" .}}
<footer></footer>
</body>
</html>
content1.gohtml
{{define "title"}}The 2hO Network{{end}}
{{define "description"}}An options description{{end}}
{{define "content"}}
Vestibulum ante ipsum primis in faucibus...
{{end}}
content2.gohtml
{{define "title"}}The 2hO Network{{end}}
{{define "content"}}
Vestibulum ante ipsum primis in faucibus...
{{end}}