Keats / tera2

37 stars 5 forks source link

feat: global contexts #25

Closed GandelXIV closed 9 months ago

GandelXIV commented 9 months ago

Currently this uses two .clones to merge global and local contexts for rendering, yet it works fine.

Example code

let mut tera = Tera::new();
tera.global_context().insert("name", "John Doe");

let content = tera
    .render_str("Hello, {{ name }}!", &Context::new())
    .unwrap();
assert_eq!(content, "Hello, John Doe!".to_string());

let content2 = tera
    .render_str(
        "UserID: {{ id }}, Username: {{ name }}",
        &context! { id => &7489 },
    )
    .unwrap();
assert_eq!(content2, "UserID: 7489, Username: John Doe");
Keats commented 9 months ago

Can you rebase? LGTM otherwise

GandelXIV commented 9 months ago

Can you rebase? LGTM otherwise

Done