pub struct TemplateEngine { /* private fields */ }
Expand description
Holds a set of templates
Implementations§
Source§impl TemplateEngine
impl TemplateEngine
pub fn new() -> Self
Sourcepub fn add_template<N, S>(&mut self, name: N, source: S) -> Result<(), Error>
pub fn add_template<N, S>(&mut self, name: N, source: S) -> Result<(), Error>
Add a named template with the specified source.
If name ends with .html
then automatical escaping of html entities
will be performed on substitutions.
Sourcepub fn get_template(&self, name: &str) -> Result<Template<'_, '_>, Error>
pub fn get_template(&self, name: &str) -> Result<Template<'_, '_>, Error>
Get a reference to a named template
Sourcepub fn add_global<N, V>(&mut self, name: N, value: V)
pub fn add_global<N, V>(&mut self, name: N, value: V)
Define a global value that can be reference by all templates
pub fn render<CTX>(
&self,
name: &str,
source: &str,
context: CTX,
) -> Result<String, Error>where
CTX: Serialize,
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TemplateEngine
impl !RefUnwindSafe for TemplateEngine
impl Send for TemplateEngine
impl Sync for TemplateEngine
impl Unpin for TemplateEngine
impl !UnwindSafe for TemplateEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more