-
Hello, I'm trying to use JINJA2_FILTERS. I've created: ...
# JINJA2_FILTERS
def to_czech_crown(number):
if number:
return '{:,}'.format(number).replace(',', ' ') + " Kč"
else:
return '---'
JINJA2_FILTERS = {'to_czech_crown': to_czech_crown}
... Now I want to use the filter in my plugin:
I found out, that the return self.render(
'inventory_monitor/invoices_include.html',
extra_context={
'object': object,
'invoices': invoices,
}
) does not call the def render_jinja2(template_code, context):
"""
Render a Jinja2 template with the provided context. Return the rendered content.
"""
import ipdb; ipdb.set_trace()
environment = SandboxedEnvironment()
environment.filters.update(get_config().JINJA2_FILTERS)
return environment.from_string(source=template_code).render(**context) How can I add custom jinja filter to be in use in template_content rendering? Edit: In the settings, I can see my custom filter:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Adding: @register.filter()
def to_czech_crown(number):
if number:
return '{:,}'.format(number).replace(',', ' ') + " Kč"
else:
return '---' To |
Beta Was this translation helpful? Give feedback.
-
@kkthxbye-code answer The feature is intended to register filters for user created templates, like webhook body template, export templates and custom links. These places use jinja2 as a template engine. The normal templates and templates used in plugins use the django templating engine and you should register templatetags for these yourself in your plugin. |
Beta Was this translation helpful? Give feedback.
-
Hi! |
Beta Was this translation helpful? Give feedback.
@kkthxbye-code answer
The feature is intended to register filters for user created templates, like webhook body template, export templates and custom links. These places use jinja2 as a template engine. The normal templates and templates used in plugins use the django templating engine and you should register templatetags for these yourself in your plugin.