Jinja - Remove whitespace using trim

by
Jeremy Canfield |
Updated: November 10 2023
| Jinja articles
trim is a Jinja2 filter used to remove whitespace from the left and right sides of a string. For example, let's say you have the following.
"{{ ' hello world ' }}"
This should output the following, where we can see whitespace before and after hello world.
" hello world "
trim can be used to remove the whitespace from the left and right sides of hello world.
"{{ ' hello world ' | trim }}"
Which should return the following.
"hello world"
Did you find this article helpful?
If so, consider buying me a coffee over at