I have a wiki web app from the go docs tutorial and want to add a few things. One of those things is a list of all wiki entries at the front page. I have a html template that looks like this:
<h1>This is the front page of the wiki</h1>
<p>here is the list of entries:</p>
<div>
<ul>
{{printf "%s" .Body}}
</ul>
</div>
And here is the handler of the page
func frontHandler(w http.ResponseWriter, r *http.Request){
entries := getEntries()
p := &Page{Title: "FrontPage", Body: []byte(entries)}
renderTemplate(w, "front", p)
}
I've formatted the list of entries to work as a ul in html, it is a splice of strings joined into one to convert it to a splice of bytes, it is formatted like this:
<li><a href="/view/page1">page1</a></li>
<li><a href="/view/page2">page2</a></li>
and so on, so i would like to render it as html instead of plain text like it is now.
I've tried changing how i pass the body of the page from a splice of bytes to a string and it had the same outcome. I tried changing how i render the page to take a different struct made specifically for the front page as a workaround but it also had no effect. Here is how i render the template
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page){
err := templates.ExecuteTemplate(w, tmpl + ".html", p)
if err != nil{
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
I've also tried a few different ways of showing it in the .html file instead of the {{printf "%s" .Body"}} and I've been unsuccessful.
Any help is much appreciated, also let me know if i should provide more info.
p := &Page{Title: "FrontPage", Body: template.HTML(entries)}