Planning to add HTMX support? #183
Unanswered
danilommarano
asked this question in
Q&A
Replies: 2 comments 1 reply
-
See the docs for attribute setting here: https://github.com/Knio/dominate#attributes |
Beta Was this translation helpful? Give feedback.
0 replies
-
This works: from dominate.tags import *
element = button(**{"hx-post": "/clicked", "hx-swap": "outerHTML"})
print(element)
# <button hx_post="/clicked" hx_swap="outerHTML"></button> You can create a Pydantic Model for HTMX attributes with aliases to achive a more beautiful syntax. Like this: from pydantic import BaseModel, Field
from dominate.tags import *
class HTMX(BaseModel):
"""HTMX attributes"""
hx_post: str = Field(None, title="Post URL", serialization_alias="hx-post")
hx_get: str = Field(None, title="Get URL", serialization_alias="hx-get")
hx_swap: str = Field(None, title="Swap with", serialization_alias="hx-swap")
htmx_attrs = HTMX(hx_post="/clicked", hx_swap="outerHTML")
element = button(**htmx_attrs.model_dump(exclude_none=True))
print(element) I don't know the every HTMX attributes there are but you can find more at htmx reference, this is just a sketch. Feel free to improve. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently is not possible to write elements with HTMX attributes. This is because every HTMX attribute uses the
-
character for namespacing, which is not accepted by Python as a variable character.At HTMX docs there is the following button example:
But when I tried to simulate it using
_
as described in the SVG readme section it didn't work.Beta Was this translation helpful? Give feedback.
All reactions