Documentation menu
Getting Started
Core Concepts
Control
Interactivity
Pushing Data
HTMX Extensions
Miscellaneous
Configuration
Loops / Dealing With Lists
Use h.List to render a slice in its existing order. Use h.IterMap to render a map when iteration order can vary.
Example: Rendering a list of tasks
func TaskList() *h.Element {
tasks := []string{"Write docs", "Review examples", "Ship release"}
return h.Ul(
h.List(tasks, func(task string, _ int) *h.Element {
return h.Li(h.Text(task))
}),
)
}
Copy
1func TaskList() *h.Element {
2 tasks := []string{"Write docs", "Review examples", "Ship release"}
3 return h.Ul(
4 h.List(tasks, func(task string, _ int) *h.Element {
5 return h.Li(h.Text(task))
6 }),
7 )
8}Example: Rendering a map
func StatusList() *h.Element {
statuses := map[string]string{
"docs": "ready",
"release": "pending",
}
return h.Ul(
h.IterMap(statuses, func(name, status string) *h.Element {
return h.Li(h.TextF("%s: %s", name, status))
}),
)
}
Copy
1func StatusList() *h.Element {
2 statuses := map[string]string{
3 "docs": "ready",
4 "release": "pending",
5 }
6 return h.Ul(
7 h.IterMap(statuses, func(name, status string) *h.Element {
8 return h.Li(h.TextF("%s: %s", name, status))
9 }),
10 )
11}