Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Liquid filters on numbers: plus, minus

  • Some filters can have parameters as well.
  • Increment or decerement the number by the given number.
fn main() {
    let template = liquid::ParserBuilder::with_stdlib()
        .build()
        .unwrap()
        .parse(
            "
           plain: {{whole}}
           plus 2: {{whole | plus : 2}}
           minus 2 {{whole | minus : 2}}

           plain: {{float}}
           plus 2: {{float | plus : 2}}
           minus 2 {{float | minus : 2}}
        ",
        )
        .unwrap();

    let whole = 42;
    let float = 4.2;

    let globals = liquid::object!({
        "whole": whole,
        "float": float,
    });
    let output = template.render(&globals).unwrap();

    println!("{}", output);
}

           plain: 42
           plus 2: 44
           minus 2 40

           plain: 4.2
           plus 2: 6.2
           minus 2 2.2
        

  • plus
  • minus