askama
askama copied to clipboard
Add documentation about custom filters
I should also document the list of built-in filters.
Would be great to have a more complete example of a custom filter.
Fair point! For now, have a look at this test case:
https://github.com/djc/askama/blob/master/testing/tests/filters.rs#L39
Thanks! I managed to make some filters with this test case as reference:
/// Any filters defined in `mod filters` are accessible in your template documents.
mod filters {
pub fn extension(s: &str) -> ::askama::Result<String> {
Ok(s.split('.').last().expect("Couldn't split by '.'").into())
}
pub fn uscore_to_space(s: &str) -> ::askama::Result<String> {
Ok(s.replace("_", " ").into())
}
}