Unfortunately that would change lots of other things.   There are IDs
generated as well within the header tags for navigation from a table of
contents

I agree I can build a workaround in many ways but I shouldn't have to.  The
whole template is html and if i don't have that variable there, just H1
hardcoded then it works.  I insert a simple variable and it breaks and yet
the variable is html.

There needs to be something in GO that should show this.  If they want to
start second guessing it the final output is safe or not then parser the
final output.  Don't get hung up on a variable.



On Sat, 14 Mar 2026, 05:22 'Dan Kortschak' via golang-nuts, <
[email protected]> wrote:

> On Fri, 2026-03-13 at 10:39 -0700, Touring Tim wrote:
> > 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)
> > }
>
> The "<" is not a template.HTML in your code. Try something like this,
> https://go.dev/play/p/zcgKpSI5stw.
>
> --
> 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/97c7fa124d84f334996a414c9c05f7ebfb86a8df.camel%40kortschak.io
> .
>

-- 
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/CADHGo%2B1etVBh1OGXpWXATyq6sPpGUbaVbwE9a731aT9osWDssg%40mail.gmail.com.

Reply via email to