pub fn render_with_vars<T, K, V, I>(
template: &str,
data: &T,
theme: &Theme,
mode: OutputMode,
vars: I,
) -> Result<String, RenderError>Expand description
Renders a template with additional variables injected into the context.
This is a convenience function for adding simple key-value pairs to the template
context without the complexity of the full ContextRegistry system. The data
fields take precedence over the injected variables.
§Arguments
template- A minijinja template stringdata- The primary serializable data to rendertheme- Theme definitions for style tag processingvars- Additional variables to inject into the template context
§Example
use standout_render::{render_with_vars, Theme, OutputMode};
use serde::Serialize;
use std::collections::HashMap;
#[derive(Serialize)]
struct User { name: String }
let theme = Theme::new();
let user = User { name: "Alice".into() };
let mut vars = HashMap::new();
vars.insert("version", "1.0.0");
vars.insert("app_name", "MyApp");
let output = render_with_vars(
"{{ name }} - {{ app_name }} v{{ version }}",
&user,
&theme,
OutputMode::Text,
vars,
).unwrap();
assert_eq!(output, "Alice - MyApp v1.0.0");