Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

Add context! macro to reduce boilerplate when building Contexts (#861) #887

Closed GandelXIV closed 5 months ago

GandelXIV commented 7 months ago

This macro greatly simplifies building Contexts, as you just pass it key-value pairs and inserts them for you.

Example:

use tera::context;
let ctx = context! {
    name => "Brian",
    age => &24
};

Expands to:

let ctx = {
    let mut context = Context::new();
    context.insert("name", "Brian");
    context.insert("age", &24);
    context
};
GandelXIV commented 7 months ago

Associated issue: #861

Keats commented 7 months ago

Can you do the PR on the v2 repo? https://github.com/Keats/tera2 It will get moved to this repo eventually

GandelXIV commented 7 months ago

Sure, here you go