Tera - list templates


I am not sure if this is ever needed in an application, but it helped me when first I could not figure out the expected directroy layout. It might be used for debugging to see if Tera can really find your templates.


$ tree
.
├── Cargo.lock
├── Cargo.toml
├── out.out
├── src
│   └── main.rs
└── templates
    ├── hello.html
    └── incl
        └── header.html


examples/tera/list-templates/src/main.rs
use tera::Tera;

fn main() {
    let tera = Tera::new("templates/*.html").unwrap();

    tera.get_template_names().for_each(|x| println!("{}", x));
}

incl/header.html
hello.html


examples/tera/list-templates/Cargo.toml
[package]
name = "hello-world"
version = "0.1.0"
edition = "2021"

[dependencies]
tera = "1.20.0"

examples/tera/list-templates/templates/hello.html
Hello, {{name}}!

examples/tera/list-templates/templates/incl/header.html
<html>
    <head>
    </head>