sunweb_templating 0.3.0

Templating engine for the SunWeb framework.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented0 out of 3 items with examples
  • Size
  • Source code size: 39.47 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 763.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 5s Average build duration of successful builds.
  • all releases: 1m 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Sunnickel/SunWeb
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Sunnickel

A lightweight template engine for the SunWeb framework.

You should not depend on this crate directly — use [sunweb] with the templating feature instead, which re-exports everything from here.

Template Syntax

Syntax Description
{{ name }} Inserts a variable from the context
{% if condition %} ... {% endif %} Conditional block
{% for item in list %} ... {% endfor %} Loop over a list

Example

use sunweb::{Context, Value, render};

let mut ctx = Context::new();
ctx.insert("title".into(), Value::from("Hello"));
ctx.insert("show_footer".into(), Value::Bool(true));
ctx.insert("users".into(), Value::List(vec![
    [("user.name".into(), Value::from("Alice"))].into(),
    [("user.name".into(), Value::from("Bob"))].into(),
]));

// template: "<h1>{{ title }}</h1>"
//           "{% if show_footer %}<footer>bye</footer>{% endif %}"
//           "{% for user in users %}<p>{{ user.name }}</p>{% endfor %}"