Answer the question
In order to leave comments, you need to log in
How to work with html/template?
Hello. Here is the function that parses the html
func Views(templateName string, p map[string]string, w http.ResponseWriter) {
t, err := template.ParseFiles("views/"+templateName)
if err != nil {
w.Header().Set("Status", "404 Not Found")
}
w.Header().Set("Content-Type", "text/html")
t.Execute(w, p)
}
{{template "head.html".}}
for _, bk := range bks {
fmt.Fprintf(w, "'%s':'%s',", bk.id, bk.name)
}
Answer the question
In order to leave comments, you need to log in
Look at https://www.youtube.com/watch?v=k27Oga3Wmxs
There is an example of how to make a simple application
{{ define "index" }}
{{ template "header" }}
{{ range $key, $value := . }}
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
<h1><a href="/edit?id={{$key}}">{{ $value.Title }}</a></h1>
</div>
<div class="col-xs-2">
</div>
</div>
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
{{ $value.Content }}
</div>
<div class="col-xs-2">
</div>
</div>
{{ end }}
{{ template "footer" }}
{{ end }}
Fuck. Why try to write your own framework when there are already a bunch of others? JSF in hand forward...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question