A package containing custom filters for jinja2
Project description
Jinja2 Custom Filters
Jinja2 offers many filters to use in your template. But this is limited. This repo offers a number of additional filters that can be used in Jinja2 templates.
How it works
-
The first and foremost is installation.
pip install jinja2_custom_filters_extension
-
Add extension to your jinja environment.
from jinja2_custom_filters_extension.string_filters_extension import StringFilterExtension environment: Environment = Environment(extensions=[StringFilterExtension])
-
Use the filters that are available in the extension as you would use a built in filter in your jinja templates.
for ex:{{ "abc DEF" | upper_case_first_letter }}
-
Render your template , the filters should be working.
Extensions
String Filter Extension
Filter Name | Description | Example Input Value | Generated Output Value |
---|---|---|---|
slug | Changes the value to lower case and then replaces spaces with dashes | aBc DeF GHi | abc-def-ghi |
upper_case_first_letter | Changes only the first letter of the value to upper case. | AbC DeF | abC DeF |
Usage with cookiecutter
cookiecutter is a famous tool for creating projects from project templates.
Itis built on top of jinja2
.
These extensions can also be used in a cookiecutter project.
-
Make sure the package
jinja2_custom_filters_extension
is installed. -
Add extensions in the
cookiecutter.json
file of your project.
Refer the link on how to do it. Bascially it is adding the below entry to the json."_extensions": ["jinja2_custom_filters_extension.string_filters_extension.StringFilterExtension"]
-
Use the filters in your templates.
-
Thats it. When you run your cookiecutter project, it should work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for jinja2_custom_filters_extension-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e27f1bbe3bdac59bd54a047c0e325d077d6e2566b9c5f7aa88e4082bdb56a788 |
|
MD5 | 101fe2edb6541461cbf720536443e0ae |
|
BLAKE2b-256 | f73c1833bf402d5909b70b690191d801ec67ac0ff240ceee5f31047e3ccf7073 |
Hashes for jinja2_custom_filters_extension-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31a4e8f672af895f55d1f50e5b1b482117d8db62bff5dc3202c7948956f2cdba |
|
MD5 | a076535c560f47d9dd1e2a299cba6e1f |
|
BLAKE2b-256 | 9c228358e838210ddeb72f7c17ef0f4c22e7695fe9a5ed4b4f1a0f7d4157311e |