Skip to main content

render_with_vars

Function render_with_vars 

Source
pub fn render_with_vars<T, K, V, I>(
    template: &str,
    data: &T,
    theme: &Theme,
    mode: OutputMode,
    vars: I,
) -> Result<String, RenderError>
where T: Serialize, K: AsRef<str>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,
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 string
  • data - The primary serializable data to render
  • theme - Theme definitions for style tag processing
  • vars - 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");