将html字符串解析为Go语言中的模板

问题描述 投票:0回答:1

我将html存储为字符串形式返回的表,我想将其插入到html模板中。目前,它只是呈现为字符串:

例如假设我的myHtmlString变量值为<h3>Hello</h3>

func (h *handler) buildEmailTemplate() model.myEmailModel {
    return model.myEmailModel {
        message: myHtmlString
    }
}

type myEmailModel {
    message: template.HTML '<h1>Hello</h1>'
}

我尝试将这个buildEmailTemplate函数更改为无法解析为template.HTML字符串:

message: template.HTML(myHtmlString)

go go-templates
1个回答
0
投票

您可以尝试this。您可以使用“ html / template”

解析预定义的HTML模板
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.