Skip to main content

path_loader

Function path_loader 

Source
pub fn path_loader<'x, P>(
    dir: P,
) -> impl for<'a> Fn(&'a str) + Send + Sync + 'static
where P: AsRef<Path> + 'x,
Expand description

Helper to load templates from a given directory.

This creates a dynamic loader which looks up templates in the given directory. Templates that start with a dot (.) or are contained in a folder starting with a dot cannot be loaded.

The loaded templates carry an up-to-date check based on the modification time and size of the file. Because auto reloading is enabled by default, templates are reloaded automatically when they change on disk. This costs a stat call per template lookup which can be avoided by disabling auto reloading.

ยงExample

fn create_env() -> Environment<'static> {
    let mut env = Environment::new();
    env.set_loader(path_loader("path/to/templates"));
    env
}