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

Applying filters to an entire block

Filters are normally reserved for writs, but occasionally it can be helpful to apply one or more filters to an entire block of content all at once.

The escaper is specified first in the statement and run last on the content, just like with writs. To prevent double escaping or confusion, writs cannot specify an escaper themselves within a filter block.

Behind the scenes, the entire block is converted into a CowStr, the filters are applied to it left to right, and finally it is escaped as it is being output.

{% filter text | lower -%}
    Hello {{ name }}!
{%- endfilter -%}
extern crate oxiplate;

use oxiplate::prelude::*;

#[derive(Oxiplate)]
#[oxiplate = "filter.html.oxip"]
struct YourStruct {
    name: &'static str,
}

assert_eq!(
    YourStruct {
        name: "Jasmine & Malachi",
    }.render()?,
    "hello jasmine & malachi!",
);

Ok::<(), ::core::fmt::Error>(())

Filters can be chained just like in writs:

{% filter text | >lower | upper -%}
    Hello {{ name }}!
{%- endfilter -%}
extern crate oxiplate;

use oxiplate::prelude::*;

#[derive(Oxiplate)]
#[oxiplate = "filter-multiple.html.oxip"]
struct YourStruct {
    name: &'static str,
}

assert_eq!(
    YourStruct {
        name: "Jasmine & Malachi",
    }.render()?,
    "HELLO JASMINE &amp; MALACHI!",
);

Ok::<(), ::core::fmt::Error>(())