render_with_json

Function render_with_json 

Source
pub fn render_with_json(
    template: &str,
    vars: HashMap<&str, Value>,
) -> Result<String>
Expand description

Render template string with JSON values

§Arguments

  • template - Template string with {{ variables }}
  • vars - Variables as JSON values

§Example

use clnrm_template::render_with_json;
use std::collections::HashMap;
use serde_json::Value;

let mut vars = HashMap::new();
vars.insert("items", Value::Array(vec![
    Value::String("apple".to_string()),
    Value::String("banana".to_string())
]));
vars.insert("enabled", Value::Bool(true));

let result = render_with_json("Items: {{ items | join(', ') }}, Enabled: {{ enabled }}", vars).unwrap();