I've started using the Go language, and am now trying to create an HTML page. I am quite new to both coding in Go and HTML.
In the Go program I'm trying to parse a HTML page (div) into a main html page (index.html) I'm trying to add this div to the main html page using a template in Go.
The html page where I'm trying to parse the data into looks like this:
<html>
<head>
<meta charset="utf-8">
<title>SmartHomePi Status</title>
<link rel="stylesheet" href="../static/css/style.css">
</head>
<body>
<h1>HomeControl Connection Status</h1>
<div id="wrapper" width="100%">
{{.SonoffBasic}}
</div>
</body>
the {{.SonoffBasic}} part is the part where I'm trying to add my div. The div I'm trying to add looks like this:
<div id="sonoffbasicdevice">
<span class="%connectiondotclass%"></span>
<p id="title">%title%</p>
<p id="tempandhum">%humstatus%</p>
<p id="ipaddress">%ipaddress%</p>
<p id="portnumber">%portnumber%</p>
</div>
All value's with %xxx% are parsed in go to contain useful information, and all goes correct.
But now I'm trying to parse those 2 together using a Template in Go, and here seems to go something wrong.
I'm doing that with the following function in Go:
func renderHomeKitTemplate(w http.ResponseWriter, tmpl string, items *WebPageHTMLItems) {
err := templates.ExecuteTemplate(w, "index.html", items)
}
Where the variable items is a struct looking like this:
type WebPageHTMLItems struct{
SonoffBasic string
}
where theSonoffBasic string contains the div with all filled in information.
The webpage can be viewed when I run the program, but when the webpage is shown, instead of parsing the div, it is shown as plain text, what am I doing wrong in here?
Is this even the correct way to parse the data into the HTML file. The reason why I'm using this way of adding a complete div, is because I can have multiple "sonoffbasicdevice" items and should add multiple of them.