TideTeraExt

Trait TideTeraExt 

Source
pub trait TideTeraExt {
    // Required methods
    fn render_response(&self, template_name: &str, context: &Context) -> Result;
    fn render_body(
        &self,
        template_name: &str,
        context: &Context,
    ) -> Result<Body>;
}
Expand description

This extension trait adds two methods to tera::Tera: render_response and render_body

Required Methods§

Source

fn render_response(&self, template_name: &str, context: &Context) -> Result

render_body returns a fully-rendered tide::Body with mime type set based on the template name file extension using the logic at tide::http::Mime::from_extension. This will return an Err variant if the render was unsuccessful.

use tide_tera::prelude::*;
let tera = tera::Tera::new("tests/templates/**/*").unwrap();
let response = tera
    .render_response("good_template.html", &context! { "name" => "tide" })
    .unwrap();
assert_eq!(response.content_type(), Some(tide::http::mime::HTML));
Source

fn render_body(&self, template_name: &str, context: &Context) -> Result<Body>

render_response returns a tide Response with a body rendered with render_body. This will return an Err variant if the render was unsuccessful.

use tide_tera::prelude::*;
let tera = tera::Tera::new("tests/templates/**/*").unwrap();
let body = tera
    .render_body("good_template.html", &context! { "name" => "tide" })
    .unwrap();
assert_eq!(body.mime(), &tide::http::mime::HTML);

Implementations on Foreign Types§

Source§

impl TideTeraExt for Tera

Source§

fn render_body(&self, template_name: &str, context: &Context) -> Result<Body>

Source§

fn render_response(&self, template_name: &str, context: &Context) -> Result

Implementors§