Documentation menu
Getting Started
Core Concepts
Control
Interactivity
Pushing Data
HTMX Extensions
Miscellaneous
Configuration
Components
Components are Go functions that build reusable pieces of HTML. A component can accept data as arguments or load data when your code calls it.
A page or partial can call the same component to render it in different parts of your application.
func TaskCard(title, description string) *h.Element {
return h.Div(
h.Class("bg-white w-full rounded shadow-md p-4"),
h.H3(h.Text(title)),
h.P(h.Text(description)),
)
}
func TaskPage(ctx *h.RequestContext) *h.Page {
return h.NewPage(
TaskCard("Review the examples", "Run each snippet before publishing."),
)
}
Copy
1func TaskCard(title, description string) *h.Element {
2 return h.Div(
3 h.Class("bg-white w-full rounded shadow-md p-4"),
4 h.H3(h.Text(title)),
5 h.P(h.Text(description)),
6 )
7}
8
9func TaskPage(ctx *h.RequestContext) *h.Page {
10 return h.NewPage(
11 TaskCard("Review the examples", "Run each snippet before publishing."),
12 )
13}Call the component directly in a page or in a partial. When htmx requests an update, the partial can render the component again with fresh data.