| Crates.io | simpletemplate |
| lib.rs | simpletemplate |
| version | 0.1.0 |
| created_at | 2022-12-20 03:17:04.252921+00 |
| updated_at | 2022-12-20 03:17:04.252921+00 |
| description | HTML template engine. |
| homepage | https://github.com/guiszk/simpletemplate |
| repository | https://github.com/guiszk/simpletemplate |
| max_upload_size | |
| id | 741919 |
| size | 14,536 |
Template engine written entirely in rust.
// 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
}
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.