In HTML file, I want to get the ID and the Username, but how to do that? because what I got always a blank page.
// DataHandler struct
type DataHandler struct {
SessionDataHandler session.SessionData
}
// HomeHandler function
func HomeHandler(w http.ResponseWriter, r *http.Request) {
sessionData := session.GetSession(w, r)
data := DataHandler{
SessionDataHandler: session.SessionData{
ID: sessionData.ID,
Username: sessionData.Username,
},
}
tmp, err := template.ParseFiles(
"web/index.html",
"web/template/header.html",
"web/template/footer.html",
)
if err != nil {
log.Fatal(err)
}
err = tmp.Execute(w, data)
if err != nil {
log.Println(err)
}
}
I already tried using these in the HTML but still no luck.
{{ .SessionDataHandler }}
{{ .SessionDataHandler.ID }}
{{ .SessionDataHandler.session.ID }}
{{ .SessionDataHandler.sessionData.ID }}
{{ .SessionDataHandler.session.sessionData.ID }}
how to call them?
Edited:
// SessionData struct
type SessionData struct {
ID int
Username string
}
Edited again: (HTML files)
{{ template "header.html" . }}
{{ .SessionDataHandler.ID }}
<!-- HOME PRO-->
<div class="home-pro">
<!-- PRO BANNER HEAD -->
<div class="banr-head">
<div class="container">
<div class="row">