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
Open

Add documentation about custom filters #102

djc opened this issue Jul 4, 2018 · 4 comments

Comments

@djc
Copy link
Owner

@djc djc commented Jul 4, 2018

No description provided.

@djc
Copy link
Owner Author

@djc 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
Copy link

@Cokemonkey11 Cokemonkey11 commented Jul 29, 2018

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

@djc
Copy link
Owner Author

@djc 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
Copy link

@Cokemonkey11 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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants