[Solved] Html template use on golang


You could send variables in map. For example:

package main

import (
    "bytes"
    "fmt"
    "text/template"
)

func main() {
    t, _ := template.New("hi").Parse("Hi {{.name}}")
    var doc bytes.Buffer
    t.Execute(&doc, map[string]string{"name": "Peter"})
    fmt.Println(doc.String()) //Hi Peter
}

solved Html template use on golang