hylian
hylian

Reputation: 560

Parse html string to template in Go

I have html stored in a table returning as a string, and I want to insert it into my html template. Currently it just renders as a string:

Eg. assume my myHtmlString var value is <h3>Hello</h3>

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

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

I've tried changing this buildEmailTemplate function to parse to a template.HTML string unsuccessfully:

message: template.HTML(myHtmlString)

Upvotes: 0

Views: 191

Answers (1)

Bekassyl
Bekassyl

Reputation: 45

Why not to leave <h1> </h1> in html and pass "hello" or whatever as usual? By default passed argument can be empty string.

Upvotes: 1

Related Questions