Filters
Filters modify expressions that precede them:
{{ "foo" | upper }}
FOO
Behind the scenes,
filters are functions
in the filters_for_oxiplate module
located in the current scope
that are passed the result of the expression
as the first argument.
Additional arguments can be passed to the filter directly:
{{ "hello world" | replace("hello", "goodbye") }}
goodbye world
Built-in filters
Oxiplate has a number of filters declared in the
filters module.
To use these on their own without any additional filters,
import ::oxiplate::filters as filters_for_oxiplate.
Or use ::oxiplate::prelude::* which does the same,
along with importing the Oxiplate macro and Render trait.
Alternatively, a custom set of filters can be built once:
extern crate oxiplate;
mod filters_for_oxiplate {
use ::oxiplate::filters::*;
// Additional filters here
}
extern crate oxiplate;
mod filters_for_oxiplate {
use ::oxiplate::filters::{lower, upper};
// Additional filters here
}
And then used throughout the package:
extern crate oxiplate;
mod filters_for_oxiplate {}
fn main() {
use ::oxiplate::{Oxiplate, Render};
use crate::filters_for_oxiplate;
// Template structs and functions to call `render()`
}
CowStr filters
CowStr is generated via the cow prefix.
| Filter | Description |
|---|---|
lower | Converts to lowercase |
trim | Trims leading and trailing whitespace |
trim_end | Trims trailing whitespace |
trim_start | Trims leading whitespace |
upper | Converts to uppercase |
Option filters
| Filter | Arguments | Description |
|---|---|---|
default | default_value | Unwraps Some value or uses default_value |