-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Template::custom but without configured template directory #1792
Comments
This actually seems pretty close to a good solution already: you could manually manage a
Note that you could also call
Yes - unfortunately this option is a lot of complexity to add especially at compile time. But I think this need should already be largely fulfilled by other compile-time template engines. |
That could work but would still require returning something else than
That's what I tried first and thought worked until i realized that they were served with mime type
Yes I didn't realize rocket was already loading the templates itself I just found the Tera docs that said |
Yes, that particluar suggestion includes to not using And ouch, I neglected to consider the content-type. The symlink solution seems appropriate since it's already working as desired, and I think it's unlikely for that approach to fundamentally change. |
Do you know if it's possible to configure |
Sure! Values can be set programmatically and used with the the |
I think there should be an option similar to |
Existing Functionality
I want to ship a single file without a templates directory.
One way it is possible now is to use a managed state Tera instance but this requires changing the routes which means it is not possible to have templates included in release and reloaded from files during development.
With
rocket.attach(Template::custom(…
it is possible tocfg!(debug_assertions)
engines.tera.add_raw_template("index.html", include_str!("../templates/index.html.tera"))
. This works but still requires an empty templates folder to be present.(Well it almost works. Since rocket strips two extensions and templates added with
add_raw_template
only one template names aren't the same in debug and release. Fortunaltely it is possible to create symlinks fromindex.html.html.tera
toindex.html.tera
and then one can useindex.html
as template name)Suggested Changes
Add
Template::fully_custom
which usesTera::default
instead ofTera::new
Alternatives Considered
I tried
engines.tera = Tera::default()
but that didn't have any effect.Adding
engines.clear_config()
which would reset the Tera instance to itsTera::defalt()
state and could be called inTemplate::custom
Ideally there would be a
Template::compiled_in_fairing()
which would behave likeTemplate::fairing
but load templates at compile time but this might be hard to implement.Full example
The text was updated successfully, but these errors were encountered: