Tera - use built-in filters on strings



examples/tera/string-filters/src/main.rs
use tera::Context;
use tera::Tera;

fn main() {
    let tera = Tera::new("templates/*.html").unwrap();

    let mut context: Context = Context::new();
    context.insert("text", " Hello, World! How are you? ");

    let result = tera.render("hello.html", &context).unwrap();
    println!("{result}");
}

examples/tera/string-filters/templates/hello.html
text:       '{{text}}'
reverse:    '{{text | reverse}}'
upper:      '{{text | upper}}'
lower:      '{{text | lower}}'
capitalize: '{{text | capitalize}}'
wordcount:  '{{text | wordcount}}'
length:     '{{text | length}}'
slugify:    '{{text | slugify}}'
title:      '{{text | title}}'
trim:       '{{text | trim}}'
trim_start: '{{text | trim_start}}'
trim_end:   '{{text | trim_end}}'

text:       ' Hello, World! How are you? '
reverse:    ' ?uoy era woH !dlroW ,olleH '
upper:      ' HELLO, WORLD! HOW ARE YOU? '
lower:      ' hello, world! how are you? '
capitalize: ' hello, world! how are you? '
wordcount:  '5'
length:     '28'
slugify:    'hello-world-how-are-you'
title:      ' Hello, World! How Are You? '
trim:       'Hello, World! How are you?'
trim_start: 'Hello, World! How are you? '
trim_end:   ' Hello, World! How are you?'