Skip to content

Loader re-loading every time #363

Closed Answered by joelmichael
joelmichael asked this question in Q&A
Discussion options

You must be logged in to vote

It seems the solution is that I need to call get_template on each template when I initialize my Environment. I tried that before, but was confused because the code I found for extracting the filename from dir entries using format!("{:?}", entry.file_name()) was adding quote characters around the string, e.g. "home.jinja" instead of home.jinja.

This works:

async fn init_jinja_env() -> minijinja::Environment<'static> {
    let mut env = minijinja::Environment::new();
    env.set_loader(minijinja::path_loader("templates"));
    if std::env::var("DEV").is_err() {
        for entry_res in std::fs::read_dir("templates").unwrap() {
            let entry = entry_res.unwrap();
            let file…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by joelmichael
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@mitsuhiko
Comment options

@joelmichael
Comment options

@mitsuhiko
Comment options

@joelmichael
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants