used block executetemplate thingy
This commit is contained in:
parent
2c52966b5c
commit
648ceae84a
6
main.go
6
main.go
@ -119,8 +119,10 @@ func main() {
|
||||
|
||||
todo_add(title, desc, done)
|
||||
|
||||
html := fmt.Sprintf("<tr><td>%s</td><td>%s</td><td>%t</td></tr>", title, desc, done)
|
||||
template.Must(template.New("t").Parse(html)).Execute(w, nil)
|
||||
todo := Todo{title, desc, done}
|
||||
|
||||
tmpl := template.Must(template.ParseFiles("tmpl/home.html"))
|
||||
tmpl.ExecuteTemplate(w, "todo-table-element", todo)
|
||||
}
|
||||
http.HandleFunc("/add-todo", add_todo)
|
||||
|
||||
|
@ -31,11 +31,13 @@
|
||||
</thead>
|
||||
<tbody id="todos">
|
||||
{{ range .Todos }}
|
||||
<tr>
|
||||
<td>{{ .Title }}</td>
|
||||
<td>{{ .Desc }}</td>
|
||||
<td>{{ .Done }}</td>
|
||||
</tr>
|
||||
{{ block "todo-table-element" . }}
|
||||
<tr>
|
||||
<td>{{ .Title }}</td>
|
||||
<td>{{ .Desc }}</td>
|
||||
<td>{{ .Done }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user