HTML template within Component class #659
Replies: 1 comment 2 replies
-
Thanks, that's the hope! 🤩 I don't think anyone else has suggested this before, so you might be the first! I think technically it should be possible because the That's why you can override the name of the template file. However, I probably wouldn't personally add this feature because it's not a workflow I particularly like -- "locality of behavior" is fine for certain things, but I like the separation of concerns of having HTML and Python separate. I realize lots of people disagree with me about this. :) I'd look at a PR if someone wants to add the code for this feature along with tests, documentation, etc, though. |
Beta Was this translation helpful? Give feedback.
-
Apologies if this has been discussed, but I couldn't seem to find it. Let me first say that I am incredibly impressed by this library. As much as I like HTMX, this takes all of the boiler plates endpoints and plumbing out of setting up reactive components. I love how it feels so native to Django.
What I’m curious about is if it would be possible to encapsulate the entirety of the HTML template within the component class. Almost like how in react, you return a template, or in vue, you can write the TS and HTML all in one file. Here is an example:
If I were to wager guess I’d say that this is not possible because that component code is called from the template so there is a chicken and the egg problem. This would play nicely with the locality of behavior pattern. This would be a great developer experience versus having to flip back-and-forth between files. I’m guessing to make this work, you’d have to implement a custom template loader to bring them into memory. Anyways, just an idea! Love the project!
Beta Was this translation helpful? Give feedback.
All reactions