New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Block fragments #824
Conversation
eb74715
to
0df34e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really impressed at how effective the strategy of abstracting the WritableBuffer
is. Very nice.
Personally this feature seems a bit odd to me. It feels like its overloading the block inheritance mechanism to do something very different that there's already other ways to do. I did re-read the thread from #568. I wonder if perhaps a more complete motivating example would be helpful, in the tests or the docs or just PR comments?
I couldn't think of a cleaner way here. Perhaps adding another node to do it, but
It's very much a convenience feature. There are already ways to do achieve the same result (macros, importing other templates). When using a library like htmx. It's pretty nice to just go slap in a couple of lines in a template file to say "hey, this something that will update", and it can. It's part of this whole "locality of behavior" idea, where you keep things as close together as possible (ideally, in the same file). htmx, Alpine.js, Tailwindcss, and all of those that are HTML first trend towards this kind of design. This is also a pretty good read: https://htmx.org/essays/template-fragments/ |
0c089c2
to
8a70365
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The direction here seems like it offers a decent amount of functionality especially relative to the limited complexity cost, so it seems reasonable to me. @vallentin / @Kijewski any thoughts?
47cac37
to
d719fff
Compare
The parser crate changes had no effect on this PR, which is great. Could I get eyes on these changes again just incase? |
@djc what do we need to merge this? I'm considering using it but since my site is going to be built in htmx this is a requirement, thanks in advance. |
I'd like a second opinion from one of the other maintainers. |
I'm also considering using this with htmx and would love to see this land. |
Same here; looking to leverage this in htmx project. Currently, I'm using minijinja and render_block, which is working nicely. Would love to move to Askama if I can, but need this feature. |
(No is also an okay answer, but would like to have that be made explicit!) |
Sorry, I won't find the time to wrap my head around this PR for the foreseeable time. At a very (very) quick glance the code looks fine, and the feature seems useful to me. |
Hi all is there any updates on this feature? Very much looking forward to seeing it land :) |
This is waiting for another round of review from me now that we have some positive acknowledgement from @Kijewski (thanks!) -- I'm having a very busy time so it may take me a bit. (If this is important to you, maybe consider sponsoring my work on Askama and other projects.) |
The feature is pretty nice and code looks good to me! Let's wait for @djc to have time to come back to it. |
88b29cf
to
2b67283
Compare
Please just rebase and squash all your changes -- right now "this branch cannot be rebased due to conflicts". |
fc0c328
to
179434c
Compare
(Failing CI now.) |
I think the error is unrelated to this PR, and it should be fixed in the current main branch. Can you please rebase, @wrapperup? |
Yep! Was just waiting on it to be fixed in main. |
179434c
to
5e04f0f
Compare
Thanks, and sorry for the long delays in getting this merged! |
Since #568 hasn't had an update in a long time, and it is a nice feature, this is a new PR to implement the proposed changes from that discussion.
This adds block fragments/partials as part of the Template derive. Here's an example of how to use it:
This also properly supports inheritance, nesting, and the
super()
macro. It does this by abstractingbuf_writable
in the generator to add the ability to discard output, except for the block that needs to be rendered.