sunweb_templating 0.4.0

Templating engine for the SunWeb framework.
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented0 out of 3 items with examples
  • Size
  • Source code size: 57.16 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 829.48 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 33s 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 Jinja2-inspired 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 (HTML-escaped by default)
{{ name | safe }} Inserts a variable without escaping
{{ name | upper }} Applies a filter
{{ name | default("x") }} Filter with argument
{# comment #} Comment — stripped from output
{% if cond %} ... {% endif %} Conditional block
{% if cond %} ... {% else %} ... {% endif %} If/else
{% if cond %} ... {% elif cond2 %} ... {% endif %} If/elif/else
{% for x in list %} ... {% endfor %} Loop over a list
{% for x in list %} ... {% else %} ... {% endfor %} Loop with empty fallback
{{ loop.index }} 1-based loop index (inside for)
{{ loop.index0 }} 0-based loop index (inside for)
{{ loop.first }} "true" on first iteration
{{ loop.last }} "true" on last iteration
{{ loop.length }} Total number of items
{% set x = value %} Set a variable in current scope
{% raw %} ... {% endraw %} Output block literally, no processing
{%- tag -%} Strip whitespace around a tag

Filters

upper, lower, capitalize, trim, length, wordcount, reverse, escape, safe, default("fallback"), replace("a","b"), truncate(n), join("-"), abs, round

Filters can be chained: {{ name | upper | truncate(10) }}

Conditions

Conditions support ==, !=, >, <, >=, <=, and, or, not.