Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about custom filters #102

Open
djc opened this Issue Jul 4, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@djc
Copy link
Owner

djc commented Jul 4, 2018

No description provided.

@djc

This comment has been minimized.

Copy link
Owner Author

djc commented Jul 14, 2018

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

@djc djc closed this in 9b79475 Jul 23, 2018

@Cokemonkey11

This comment has been minimized.

Copy link

Cokemonkey11 commented Jul 29, 2018

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

@djc

This comment has been minimized.

Copy link
Owner Author

djc commented Jul 29, 2018

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

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

@djc djc reopened this Jul 29, 2018

@Cokemonkey11

This comment has been minimized.

Copy link

Cokemonkey11 commented Jul 31, 2018

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())
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.