How to use templui with datastar, htmx, etc? #434
|
I'm new to both templ and, especialy, templui, so I don't know how to add attributes to the components. Here's the code in the Button documentation package showcase
import "github.com/templui/templui/internal/components/button"
templ ButtonDefault() {
@button.Button() {
Button
}
}How would I replicate this datastar Click To Edit example with TemplUI? <div id="demo">
<p>First Name: John</p>
<p>Last Name: Doe</p>
<p>Email: joe@blow.com</p>
<div role="group">
<button
class="info"
data-indicator-_fetching
data-attr-disabled="$_fetching"
data-on-click="@get('/examples/click_to_edit/edit')"
>
Edit
</button>
<button
class="warning"
data-indicator-_fetching
data-attr-disabled="$_fetching"
data-on-click="@patch('/examples/click_to_edit/reset')"
>
Reset
</button>
</div>
</div>I assume it is very easy, but I can't find any relevant documentation in templui |
Answered by
axadrn
Sep 30, 2025
Replies: 1 comment 3 replies
|
Thanks for the follow-up! I had misread your earlier comment. If your question is just about adding custom attributes (for Datastar/HTMX etc.), you can do that via the Example: @button.Button(button.Props{
Variant: button.VariantSecondary,
Attributes: templ.Attributes{
"data-on-click": "@patch('/examples/click_to_edit/reset')",
"data-attr-disabled": "$_fetching",
},
}) {
Reset
}📚 References: That way you can pass through any Datastar/HTMX attributes directly to the component. |
3 replies
Answer selected by
nickchomey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the follow-up! I had misread your earlier comment. If your question is just about adding custom attributes (for Datastar/HTMX etc.), you can do that via the
Attributesfield in the props.Example:
📚 References:
That way you can pass through any Datastar/HTMX attributes directly to the component.