Skip to content
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

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

Open
txtyash opened this issue Feb 4, 2024 · 3 comments
Open

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

txtyash opened this issue Feb 4, 2024 · 3 comments

Comments

@txtyash
Copy link

txtyash commented Feb 4, 2024

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
Copy link
Owner

Keats commented Feb 4, 2024

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

@txtyash
Copy link
Author

txtyash commented Feb 5, 2024

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

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

@schungx
Copy link

schungx commented Mar 16, 2024

Not currently. I was thinking of adding a render_macro for v2 (Keats/tera2#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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants