pub struct Templates { /* private fields */ }Expand description
Implementations§
Source§impl Templates
impl Templates
Sourcepub fn new(glob: impl Into<String>) -> Result<Self, ViewError>
pub fn new(glob: impl Into<String>) -> Result<Self, ViewError>
Create a new template engine from a glob pattern
The glob pattern specifies which files to load as templates. Common patterns:
templates/**/*.html- All HTML files in templates directoryviews/*.tera- All .tera files in views directory
§Errors
Returns an error if the glob pattern is invalid or templates fail to parse.
Sourcepub fn with_config(config: TemplatesConfig) -> Result<Self, ViewError>
pub fn with_config(config: TemplatesConfig) -> Result<Self, ViewError>
Create a new template engine with configuration
Sourcepub async fn add_template(
&self,
name: impl Into<String>,
content: impl Into<String>,
) -> Result<(), ViewError>
pub async fn add_template( &self, name: impl Into<String>, content: impl Into<String>, ) -> Result<(), ViewError>
Add a template from a string
Sourcepub async fn render(
&self,
template: &str,
context: &Context,
) -> Result<String, ViewError>
pub async fn render( &self, template: &str, context: &Context, ) -> Result<String, ViewError>
Render a template with the given context
Sourcepub async fn render_with<T: Serialize>(
&self,
template: &str,
data: &T,
) -> Result<String, ViewError>
pub async fn render_with<T: Serialize>( &self, template: &str, data: &T, ) -> Result<String, ViewError>
Render a template with a serializable context
Sourcepub async fn has_template(&self, name: &str) -> bool
pub async fn has_template(&self, name: &str) -> bool
Check if a template exists
Sourcepub async fn template_names(&self) -> Vec<String>
pub async fn template_names(&self) -> Vec<String>
Get all template names
Sourcepub fn config(&self) -> &TemplatesConfig
pub fn config(&self) -> &TemplatesConfig
Get the configuration
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Templates
impl !RefUnwindSafe for Templates
impl Send for Templates
impl Sync for Templates
impl Unpin for Templates
impl !UnwindSafe for Templates
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