Closed ghickman closed 10 months ago
Hey @ghickman — good question!
I specifically had partials defined at the top, for two reasons:
So I don't want to get rid of the current behaviour
Nonetheless, I guess because folks have been using render-block, the idea of having them inline has come up a couple of times now.
So… 🤔
DefinePartialNode
, that's the result of a {% startpartial ... %}{%endpartial %}
pair, doesn't output it's content directly;
Perhaps it could though with an added inline
argument... {% startpartial partial-name inline=True %}
(or similar)
Would you fancy investigating that? (Any inline
should default to False
. Declaring a partial outside of a block generally means it wouldn't be output anyway, but where you're not using extends
it would be, so I'd want it to be opt-in)
specifically had partials defined at the top, for two reasons
Both make good sense!
How do you feel about the changes I've proposed in #9?
I've just re-read the very end of your comment and need to test out my changes in that context, but do you think I'm on the right path in terms of the tag's API?
Hey @ghickman. First pass looks good yes 👍 Please fiddle until you're happy and then let me know.
🏎️
@ghickman Did you want to look any further at this, or is it ready to go from your PoV? (No sure from the conversation…)
Thanks!
Hi @carltongibson, sorry for the slow reply, life&work got in the way!
I think this is ready for a review now please. I've got a local test project where I've tested the various scenarios out to confirm to myself it's doing what you expected, so hopefully it covers all your use cases too 🤞
Great. Thanks @ghickman!
I'm just waiting for a follow up on #11 and then I'm going to bundle up a new version.
Fixed by https://github.com/carltongibson/django-template-partials/pull/9. New version in the next week or so.
Sometimes it’s useful to have an existing section of a page re-used in another view. The below example is a boiled down example from a real life app. It’s a page with a form, where another page displays just the form in a modal with HTMX.
Defining the partial at the top of the full page template works, and referencing that partial with the # syntax in an HTMX view is already a big improvement. But I wonder if the partial template tag could be used inline in the main template too? It feels like it fits with Locality of Behaviour, however the project examples suggest the design was tailored more to reuse of template sections (one could call those components!), so I’m unsure if supporting inline definitions is desired here. What do you think?
Apologies if there is a better place to raise this and thank you for pushing forward this idea in the community!