mitsuhiko / minijinja

MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
https://docs.rs/minijinja/
Apache License 2.0
1.63k stars 95 forks source link

How can env.add_function call asynchronous functions #526

Closed sunkaifei closed 4 months ago

sunkaifei commented 4 months ago

Do you know anything? Because if all templates can call asynchronous data in the form of tags, the controller does not need to call the database, making template development very convenient.

mitsuhiko commented 4 months ago

This example shows how you can invoke async functions in your templates: https://github.com/mitsuhiko/minijinja/blob/main/examples/object-using-async/src/main.rs

What call_method there is doing you can also do in a function added with add_function. You would however need to pass the handle by other means.

mitsuhiko commented 4 months ago

I added a better example here: https://github.com/mitsuhiko/minijinja/blob/main/examples/function-using-async/src/main.rs

sunkaifei commented 4 months ago

Dear author, hello. I was unsuccessful in trying under activx_web because I wanted the template to be able to automatically reload and also have the add_function to call asynchronous functions. As I have just started working with this engine, it is challenging for beginners to write an example that can both automatically reload templates and call asynchronous functions. If you have time, I hope you can provide an example of activx_web to facilitate our learning. Thank you very much for your prompt reply. Thank you