Answer the question
In order to leave comments, you need to log in
How to pass special characters to a template in golang?
It is necessary to transfer such character & # 9654; in templates, how can this be done?
Spaces made the character not appear in the question.
When compiling, it swears at #
Answer the question
In order to leave comments, you need to log in
Just enclose the character itself in quotes, not ▶
, but the character itself.
datas = Data{
"▶",
}
package main
import (
"bytes"
"fmt"
"html/template"
)
func main() {
t, err := template.New("index").Parse("Symbol: {{.play.Symbol}}")
if err != nil {
panic(err)
}
type Data struct{ Symbol string }
var out_data = make(map[string]Data)
datas := Data{
"▶",
}
out_data["play"] = datas
b := bytes.NewBuffer([]byte{})
err = t.ExecuteTemplate(b, "index", out_data)
if err != nil {
panic(err)
}
fmt.Println(string(b.Bytes()))
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question