used block executetemplate thingy

This commit is contained in:
Maximilian Wagner 2024-02-19 21:04:58 +01:00
parent 2c52966b5c
commit 648ceae84a
2 changed files with 11 additions and 7 deletions

View File

@ -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)

View File

@ -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>