4 ms·
How do you make reusable components with HTMX?
by tail_exchange 3y ago
How do you make reusable components with HTMX?
- clivestaples 3y agoHere's how I do it in HTMX with Rails: https://viewcomponent.org/ https://viewcomponent.org/
- traverseda 3y agoYou don't, you make reusable components in your template language or framework or whatever it is you're using to generate HTML. Most have pretty good support for template re-use and hierarchy and stuff. In my preferred template language, jinja2, you'd write a macro. https://jinja.palletsprojects.com/en/3.0.x/templates/#macros https://jinja.palletsprojects.com/en/3.0.x/templates/#macros
- wry_discontent 3y agoI used htmx with Clojure and it was easy to mimic components as functions that return hiccup. I have a default middleware that converts it to html before sending it to the client unless I explicitly say it's a json route. (defn some-component [{:keys [class]} & children] [:div {:class (str "some-component-wrapper" class)} [:h1 "Hello World"] children])
- mindaslab 3y agoI wish I was working in Clojure. It seems to be such a good language.