simpletemplate

Crates.iosimpletemplate
lib.rssimpletemplate
version0.1.0
sourcesrc
created_at2022-12-20 03:17:04.252921
updated_at2022-12-20 03:17:04.252921
descriptionHTML template engine.
homepagehttps://github.com/guiszk/simpletemplate
repositoryhttps://github.com/guiszk/simpletemplate
max_upload_size
id741919
size14,536
suzuki (guiszk)

documentation

README

simpletemplate

Template engine written entirely in rust.

usage

// main.rs
use simpletemplate::render;
use serde_json::{json};

fn main() {
    let data = json!({
        "name": ["Bob Belcher"],
    });
    let content = "{{ name }}";
    let res = render(content, data);
    println!("{}", res); //returns Bob Belcher
}

template usage

For variables, use {{ variable_name }}.

For array indexing, use {{ array_name[index] }}.

To iterate over an array:

{{ for loop_variable in loop_iterable }} 
    loop_body 
{{ endfor }}

To access the index:

{{ for loop_variable in loop_iterable }} 
    {{ index }}
{{ endfor }}

If statements: if_body is rendered if condition is not null, false, or "false".

{{ if condition }} 
    if_body 
{{ else }} 
    else_body 
{{ endif }} 

View src/main.rs to see how to render from an HTML file.

Commit count: 6

cargo fmt