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
File details
Details for the file jinja2_custom_filters_extension-0.0.2.tar.gz
.
File metadata
- Download URL: jinja2_custom_filters_extension-0.0.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3fa6e574fb7b07cb4bb40a8e2639fc755c7ad2e9879d279a30d65c299df5edc |
|
MD5 | e81888e20bce357d844295779f534c01 |
|
BLAKE2b-256 | 1120bf931e08c0731d0927e5fa66b339f679381dd3f772c77da1cb766c0ee339 |
File details
Details for the file jinja2_custom_filters_extension-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: jinja2_custom_filters_extension-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 496310ec5db4da7255d0ac725b309528e708c8bdadc538bc0b1e6f95a2519eca |
|
MD5 | fc0b0a48c264d1f08bc76bbc567d228a |
|
BLAKE2b-256 | ca9dd725f77e88fd1ff49d9882371e7250ef253a6c4512ef13054e8128e6d02b |