Saving and Retrieving HTML from Database correctly?

Hello everyone,
I am trying to save the HTML from summernote on a Postgresql DB and then retrieving it later to display it in a product page.
This is the code for saving the product:

    func addProductToDB(product productsDB) {
	sqlStatement := `
	UPDATE product_information
	SET title = $2,description = $3,current_price = $4,old_price = $5, category_id=$6
	WHERE id = $1`
	_, err := db.Exec(sqlStatement, product.Id, product.Title, product.Description, product.Current_Price, product.Current_Price, product.Category)
	if err != nil {
		panic(err)
	}
}

and this is how i display it

func showProductHandler(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	id, err := strconv.ParseInt(r.FormValue("id"), 10, 32)
	checkErr(err)
	product := getSingleProductFromDB(id)
	html := string(productTemplate)
	ctx := plush.NewContext()
	ctx.Set("product", product)
	ctx.Set("productId", id)
	s, _ := plush.Render(html, ctx)
	fmt.Fprint(w, s)
}

The problem is that the html appears sanitized(if that’s the correct word).Basically it shows up as plain text.I assume this is done as a safety measure.How would i go about the text formatted as it was written.
Best Regads

1 Like

Try setting the content type in the Headers on the ResponseWriter to something like “text/html”.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.