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§
Sourcefn render_response(&self, template_name: &str, context: &Context) -> Result
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));Sourcefn render_body(&self, template_name: &str, context: &Context) -> Result<Body>
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);