askama icon indicating copy to clipboard operation
askama copied to clipboard

Add documentation about custom filters

Open djc opened this issue 6 years ago • 4 comments

djc avatar Jul 04 '18 06:07 djc

I should also document the list of built-in filters.

djc avatar Jul 14 '18 13:07 djc

Would be great to have a more complete example of a custom filter.

Cokemonkey11 avatar Jul 29 '18 17:07 Cokemonkey11

Fair point! For now, have a look at this test case:

https://github.com/djc/askama/blob/master/testing/tests/filters.rs#L39

djc avatar Jul 29 '18 19:07 djc

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())
    }
}

Cokemonkey11 avatar Jul 31 '18 11:07 Cokemonkey11