Jinja2 Tutorial – Part 4 – Template filters
This is part 4 of Jinja2 tutorial where we continue looking at the language features, specifically we'll be discussing template filters. We'll see what filters are and how we can use them in our templates. I'll also show you how you can write your own custom filters.
Jinja2 Tutorial series
- Jinja2 Tutorial - Part 1 - Introduction and variable substitution
- Jinja2 Tutorial - Part 2 - Loops and conditionals
- Jinja2 Tutorial - Part 3 - Whitespace control
- Jinja2 Tutorial - Part 4 - Template filters
- Jinja2 Tutorial - Part 5 - Macros
- Jinja2 Tutorial - Part 6 - Include and Import
- J2Live - Online Jinja2 Parser
Contents
- Overview of Jinja2 filters
- Multiple arguments
- Chaining filters
- Additional filters and custom filters
- Why use filters?
- When not to use filters?
- Writing your own filters
- Fixing "too clever" solution with Ansible custom filter
- Custom filters in Ansible
- Jinja2 Filters - Usage examples
- Conclusion
- References
- GitHub repository with resources for this post
Overview of Jinja2 filters
Let's jump straight in. Jinja2 filter is something we use to transform data held in variables. We apply filters by placing pipe symbol | Continue reading




