Yarte, Yet Another Rust Template Engine, is a handlebars-like template engine


Yarte stands for Yet Another Rust Template Engine, and is a handlebars-like template engine implemented in rust. Developers familiar with Handlebars will find syntax is very intuitive. Create templates invoking structs, using conditionals, loops, rust code, and predefined functions and templates.

edit: Yarte 0.1.0 will be ready for spring
0.0.* with new features in crates.io


Thank you for developing and making this crate available to others.

From what I can tell, Yarte works with standard Rust – that is, it does not require Nightly. Is that correct?

Also, can you discuss whether nesting is supported by Yarte and, if so, to what extent?

Finally, if you haven’t seen it already, you may want to look at the work that has been done on this recently announced crate:

Display As

It makes it possible to embed Rust itself into templates, and since you offer similar support in Yarte, you may be able to leverage some of the learnings from the development of Display As.

1 Like

You are welcome. It works in rust stable. The idea is that you can use anything that can parser syn within handlebars expression. Currently you can nest many things, you can find examples in https://github.com/rust-iendo/yarte/blob/master/testing/tests/expr.rs

Example Each if let Some

Hello, {{#each conditions}}
    {{#-if let Some(check) = cond }}
        {{#-if check }}
            {{ let cond = if check { \"foo\" } else { \"\"} }}
                if check {
                } else if let Some(cond) = key.cond {
                    if cond {
                    } else {
                } else {
        {{- else if let Some(_) = cond }}
        {{- else if let Some(cond) = key.check }}
            {{#-if cond -}}
            {{/-if }}
        {{- else -}}
            {{ cond.is_some() }}
        {{ cond.is_some() && true }}
    {{-else if let Some(cond) = check }}
        {{#-if cond -}}
    {{- else -}}

Example let loop

{{ let mut a = name.chars() }}
{{ let b: String = loop {
        if a.next().is_none() && true {
            let mut a = name.repeat(1);
            break a.repeat(2);
        } else {
}}{{ b }}