tera icon indicating copy to clipboard operation
tera copied to clipboard

Streamable templates

Open evroon opened this issue 1 year ago • 4 comments

I found this issue: https://github.com/Keats/tera/issues/211 but it has been closed for the last 5 years without update.

So I wondered whether this is something that's still being considered. I think it makes a lot of sense to support streaming, both for better user experience in for example webserver responses, but most of all as it reduces RAM usage.

To be more precise: with streaming I mean that the renderer can take an iterator as input and loop over all items of the input to generate the template. The output of the renderer is then not a string, but something that implements the Write trait.

minijinja does support streaming for example, but I would prefer not to use minijinja for other reasons.

evroon avatar Dec 18 '24 12:12 evroon

Does https://docs.rs/tera/latest/tera/struct.Tera.html#method.render_to not work for you?

Keats avatar Dec 18 '24 13:12 Keats

Ah that solves the second part of my problem, but is there a way to pass variables of type iterator to the template's context? Like what happens here

evroon avatar Dec 18 '24 13:12 evroon

No, not currently. It could maybe be added to v2 (https://github.com/Keats/tera2) but that would be a significant amount of work that I wouldn't have time to do myself

Keats avatar Dec 18 '24 13:12 Keats

Ah okay, understandable, thanks for letting me know

evroon avatar Dec 18 '24 13:12 evroon