The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Using Multiple MiniJijna Templates Via Includes

TODO: Pull subtitle into page object
Code
use minijinja::Environment;
use serde_json::{Result, Value};

pub fn multiple_templates_with_includes() -> Result<()> {
    let mut env = Environment::new();

    let base_string = r#"
<div>Hello, {% include "name" %}</div>
"#;

    let name_block_string = r#"
<strong>World</strong>
"#;

    env.add_template("base", base_string).unwrap();
    env.add_template("name", name_block_string).unwrap();

    let json_string = r#"{ "name": "World" }"#;
    let json_data: Value = serde_json::from_str(json_string)?;

    let tmpl = env.get_template("base").unwrap();
    println!("{}", tmpl.render(json_data).unwrap());
    Ok(())
}

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Using Multiple MiniJijna Templates Via Includes

This is a basic example of how to use multiple 
templates in Minijinja via includes. (It looks
like the main way things are done is with 
extends blocks. I haven't been able to get 
them to work yet.)


-- code
-- rust

use minijinja::Environment;
use serde_json::{Result, Value};

pub fn multiple_templates_with_includes() -> Result<()> {
    let mut env = Environment::new();

    let base_string = r#"
<div>Hello, {% include "name" %}</div>
"#;

    let name_block_string = r#"
<strong>World</strong>
"#;

    env.add_template("base", base_string).unwrap();
    env.add_template("name", name_block_string).unwrap();

    let json_string = r#"{ "name": "World" }"#;
    let json_data: Value = serde_json::from_str(json_string)?;

    let tmpl = env.get_template("base").unwrap();
    println!("{}", tmpl.render(json_data).unwrap());
    Ok(())
}


-- blurb

One possible way to use multiple templates in the MiniJinja Rust crate


-- categories
-- Rust
-- Minijinja


-- metadata
-- date: 2023-03-22 19:35:55
-- id: 2nohlvaq
-- site: aws
-- type: post
-- status: published