-
Notifications
You must be signed in to change notification settings - Fork 2
Component
Thanatat Tamtan edited this page Sep 23, 2023
·
7 revisions
Component can be used to render inside template, or render as standalone html (for htmx!).
t := app.Template()
t.ParseComponent("table-body", `
{{range .}}
<tr>
<td>{{.ID}}</td>
<td>{{.Name}}</td>
</tr>
{{end}}
`)
t.Parse("index", `
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{component "table-body" .List}}
</tbody>
</table>
`)func tableBody(ctx *hime.Context) error {
data := getData()
return ctx.Component("table-body", data)
}func tableBody(ctx *hime.Context) error {
data := getData()
return ctx.Render(`
{{range .}}
<tr>
<td>{{.ID}}</td>
<td>{{.Name}}</td>
</tr>
{{end}}
`, data)
}