So right now .Scan() is not taking in the type template.HTML; it completely ignores it and outputs nothing to the HTML. This is the one thing I am stuck on and uncertain about.
If I pass it as a string it works, but the HTML outputs as escaped characters
<h2>metus congue
If there is an alternative solution that would be neat.
The code is a one pager- full page here: http://pastebin.com/E4jXiv6p
The Struct
type Pages struct {
Name string
Url string
Title string
Description string
H1 string
Hero string
Contents template.HTML
Sidebar string
Page_list [][]string
}
Querying pages
func db_query_pages(db *sql.DB, err error, page_list [][]string) {
var name, url, title, description, h1, hero, sidebar string
var contents template.HTML
rows, err := db.Query("SELECT * FROM pages")
for rows.Next() {
rows.Scan(&name, &url, &title, &description, &h1, &hero, &contents, &sidebar)
page := &Pages{
Name: name,
Url: url,
Title: title,
Description: description,
H1: h1,
Hero: hero,
Contents: contents,
Sidebar: sidebar,
Page_list: page_list,
}
render_page(page)
}
}
Rendering pages
func render_page(new_page *Pages) {
http.HandleFunc(new_page.Url,
func(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "main", new_page)
})
}
HTML
{{define "content"}}
<h1>{{.H1}}</h1>
<img class="margin-bottom-md block common-border padding-md" src="{{.Hero}}">
{{.Contents}}
{{end}}