Struct tera::Tera [] [src]

pub struct Tera { /* fields omitted */ }

The main point of interaction in this library.

Methods

impl Tera
[src]

Create a new instance of Tera, containing all the parsed templates found in the dir glob

The example below is what the compile_templates macros expands to.

match Tera::new("templates/**/*") {
    Ok(t) => t,
    Err(e) => {
        println!("Parsing error(s): {}", e);
        ::std::process::exit(1);
    }
}

Renders a Tera template given a Context object.

To render a template with an empty context, simply pass a new Context object

tera.render("hello.html", Context::new());

Renders a Tera template given a Serializeable object.

If data is not an object, an error will be returned.

tera.render("hello.html", &user);

Add a single template to the Tera instance

This will error if the inheritance chain can't be built, such as adding a child template without the parent one. If you want to add several templates, use Tera::add_templates

tera.add_template("new.html", "Blabla");

Add all the templates given to the Tera instance

This will error if the inheritance chain can't be built, such as adding a child template without the parent one.

tera.add_templates(vec![
    ("new.html", "blabla"),
    ("new2.html", "hello"),
]);

Register a filter with Tera.

If a filter with that name already exists, it will be overwritten

tera.register_filter("upper", string::upper);

Register a tester with Tera.

If a tester with that name already exists, it will be overwritten

tera.register_tester("odd", testers::odd);

Select which suffix(es) to automatically do HTML escaping on, [".html", ".htm", ".xml"] by default.

Only call this function if you wish to change the defaults.

 // escape only files ending with `.php.html`
 tera.autoescape_on(vec![".php.html"]);
 // disable autoescaping completely
 tera.autoescape_on(vec![]);

Trait Implementations

impl Default for Tera
[src]

Returns the "default value" for a type. Read more

impl Debug for Tera
[src]

Formats the value using the given formatter.