pub struct MiniJinjaEngine { /* private fields */ }Expand description
MiniJinja-based template engine.
This is the default template engine, providing full template functionality:
- Jinja2-compatible syntax
- Loops, conditionals, macros
- Custom filters and functions
- Template includes
§Example
use standout_render::template::MiniJinjaEngine;
use standout_render::template::TemplateEngine;
use serde::Serialize;
use serde_json::json;
#[derive(Serialize)]
struct Data { name: String }
let engine = MiniJinjaEngine::new();
let data = Data { name: "World".into() };
let data_value = serde_json::to_value(&data).unwrap();
let output = engine.render_template(
"Hello, {{ name }}!",
&data_value,
).unwrap();
assert_eq!(output, "Hello, World!");Implementations§
Source§impl MiniJinjaEngine
impl MiniJinjaEngine
Sourcepub fn environment(&self) -> &Environment<'static>
pub fn environment(&self) -> &Environment<'static>
Returns a reference to the underlying MiniJinja environment.
This allows advanced users to register custom filters, functions, or configure the environment directly.
Sourcepub fn environment_mut(&mut self) -> &mut Environment<'static>
pub fn environment_mut(&mut self) -> &mut Environment<'static>
Returns a mutable reference to the underlying MiniJinja environment.
This allows advanced users to register custom filters, functions, or configure the environment directly.
Trait Implementations§
Source§impl Default for MiniJinjaEngine
impl Default for MiniJinjaEngine
Source§impl TemplateEngine for MiniJinjaEngine
impl TemplateEngine for MiniJinjaEngine
Source§fn render_template(
&self,
template: &str,
data: &Value,
) -> Result<String, RenderError>
fn render_template( &self, template: &str, data: &Value, ) -> Result<String, RenderError>
Renders a template string with the given data. Read more
Source§fn add_template(&mut self, name: &str, source: &str) -> Result<(), RenderError>
fn add_template(&mut self, name: &str, source: &str) -> Result<(), RenderError>
Adds a named template to the engine. Read more
Source§fn render_named(&self, name: &str, data: &Value) -> Result<String, RenderError>
fn render_named(&self, name: &str, data: &Value) -> Result<String, RenderError>
Renders a previously registered template. Read more
Source§fn has_template(&self, name: &str) -> bool
fn has_template(&self, name: &str) -> bool
Checks if a template with the given name exists.
Source§fn render_with_context(
&self,
template: &str,
data: &Value,
context: HashMap<String, Value>,
) -> Result<String, RenderError>
fn render_with_context( &self, template: &str, data: &Value, context: HashMap<String, Value>, ) -> Result<String, RenderError>
Renders a template with additional context values merged in. Read more
Source§fn supports_includes(&self) -> bool
fn supports_includes(&self) -> bool
Whether this engine supports template includes (
{% include %}).Source§fn supports_filters(&self) -> bool
fn supports_filters(&self) -> bool
Whether this engine supports filters (
{{ value | filter }}).Source§fn supports_control_flow(&self) -> bool
fn supports_control_flow(&self) -> bool
Whether this engine supports control flow (
{% for %}, {% if %}).Auto Trait Implementations§
impl !Freeze for MiniJinjaEngine
impl !RefUnwindSafe for MiniJinjaEngine
impl Send for MiniJinjaEngine
impl Sync for MiniJinjaEngine
impl Unpin for MiniJinjaEngine
impl !UnwindSafe for MiniJinjaEngine
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