Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.56k stars 285 forks source link

Is there a function similar to minijinja's render_block? #896

Open txtyash opened 9 months ago

txtyash commented 9 months ago

Minijinja has this render_block method https://docs.rs/minijinja/latest/minijinja/struct.State.html#method.render_block Is there anything similar?

I was facing a problem where I wanted to render small divs for which I have to create separate files.

Keats commented 9 months ago

Not currently. I was thinking of adding a render_macro for v2 (https://github.com/Keats/tera2/issues/27) but do people prefer blocks?

txtyash commented 9 months ago

Not currently. I was thinking of adding a render_macro for v2 (https://github.com/Keats/tera2/issues/27) but do people prefer blocks?

The problem I am dealing with is file redundancy for little divs.

schungx commented 8 months ago

Not currently. I was thinking of adding a render_macro for v2 (https://github.com/Keats/tera2/issues/27) but do people prefer blocks?

Blocks or macros are both fine for me, just any way to render a subset of a full file.

This will avoid having hundreds of small snippet files, which each of them must be individually imported in order to run. Being able to group them into a single file and then render one of them will solve a lot of problems.

Curiously, right now templates can do this by rendering a single macro out of a file of macros, but Rust has no way of doing the same short of rendering the entire file. This, to me, is an omission that should be fixed.

As to the question of blocks vs macros, personally I find macros versatile, except for the large number of parameters. It would help heaps if Tera can specify a hash object that I can pass into a macro as one single parameter instead of having to flatten them all out. Some of my more complex macros have 20+ parameters!