0

I want to render templete like this, but I can't find relative code from website.

page.tmpl

<html>
  <body>
  {{.a}}
  </body>
<html>

router code piece

aEle = `<a>I 'm tagA</a>`
r.GET("/page", func(c *gin.Context) {
  c.HTML(200, "page.tmpl",  gin.H{"a":aEle,}})
})

result like this

page
<html>
  <body>
    <a>I'‘m tagA</a>
  </body>
<html>
solomneye
  • 1
  • 1
  • [`html/template`](https://golang.org/pkg/html/template/) package. E.g. [`Template.Execute()`](https://golang.org/pkg/html/template/#Template.Execute) method. – icza Jul 17 '19 at 14:39
  • Possible duplicate of [Go template.ExecuteTemplate include html](https://stackoverflow.com/questions/18175630/go-template-executetemplate-include-html) – Peter Jul 17 '19 at 15:11

1 Answers1

0

I believe you can just do:

var aEle template.HTML = `<a>I 'm tagA</a>`
dave
  • 62,300
  • 5
  • 72
  • 93