I want to change the tags from H1 to H2 dynamically based upon if something
is a report or sub-report.
However even though the variable I use is a template.HTML which is meant to
be safe, still GO is auto escaping stuff.
Thanks in advance
Tim
-----------------------
package main
import (
"html/template"
"os"
)
type PageData struct {
HeadingLevel template.HTML // e.g., "h1" or "h2"
Title string
}
func main() {
// 1. Define the template with a variable tag
tmpl := `
<{{.HeadingLevel}}>{{.Title}}</{{.HeadingLevel}}>
`
t := template.Must(template.New("index").Parse(tmpl))
// 2. Data to pass to the template
data := PageData{
HeadingLevel: template.HTML("h1"), // This determines the tag
Title: "Hello, World!",
}
// 3. Execute
t.Execute(os.Stdout, data)
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/4a9c7908-7b0f-4f74-b85c-e5c9bb979d1fn%40googlegroups.com.