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

Reload template on the fly #273

Closed
technic opened this issue Nov 23, 2019 · 8 comments
Closed

Reload template on the fly #273

technic opened this issue Nov 23, 2019 · 8 comments

Comments

@technic
Copy link
Contributor

technic commented Nov 23, 2019

Hi, thanks for providing jinja2 experience in rust!

Feature request:

I am missing a watch and auto template reload feature, which is useful when I am finished with rust backend and start with html/js part.

The handlebars counter-part has this feature

@djc
Copy link
Owner

djc commented Nov 23, 2019

Since Askama templates get built into your application at compile time, you could probably use cargo watch to do something like this.

@technic
Copy link
Contributor Author

technic commented Nov 24, 2019

Hi thanks, that is one solution. However, it is a bit slow to launch cargo run every time. I think some reloading of html assuming that the template struct did not changed would be nice, but I don't know whether it is possible due to strong typing.

@djc
Copy link
Owner

djc commented Nov 25, 2019

This is not possible. Templates are transpiled into Rust code which is compiled into the application binary. As such, you cannot really reload only the templates. I suppose it's possible to build your application in a way such that all template code is contained in a dynamically linked library, which you could theoretically hot-reload if any template code changes. But I would say this is well outside Askama's scope.

It might be possible to use Tera for development and Askama for production -- I don't know how different the Tera and Askama syntaxes are, exactly.

@djc djc closed this as completed Nov 25, 2019
@technic
Copy link
Contributor Author

technic commented Nov 25, 2019

Thanks for the answers!
Unfortunately Tera and Askama are somewhat similar but not compatible for this scenario.

@djc
Copy link
Owner

djc commented Nov 25, 2019

If there are particular syntax-level incompatibilities, I'm open to having some alternative syntax be implemented as part of Askama (there is already some support for alternative template syntaxes).

@technic
Copy link
Contributor Author

technic commented Nov 25, 2019

What I can see immediately is the following difference: set instead of let, elif instead of else if.
Of course there is no method() support in Tera for example, so in general Tera more limiting because AFAIK it sees rust structs as json serialized objects. But maybe using in my templates only subset of features would be fine.

(there is already some support for alternative template syntaxes)

Are you talking about choosing different brackets in config?

@djc
Copy link
Owner

djc commented Nov 25, 2019

We could probably easily support set and elif in the parser if those are the only material differences.

Yes, the configuration for different brackets is built on top of a more-or-less general mechanism for parametrizing the parser.

@alper
Copy link

alper commented Sep 3, 2022

I suppose it's possible to build your application in a way such that all template code is contained in a dynamically linked library, which you could theoretically hot-reload if any template code changes. But I would say this is well outside Askama's scope.

I think it would be good to set the stage for projects to do this. Hot reloading seems to be a bit of a dark art in Rust still but hopefully we can at some point do this.

Development speed at the moment is a fraction of how you would do something in Python.

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