I have defined some filters and use it very often. I need to do some A/B tests and for this in some situations some of filters should work in different way.
Easiest way to do this would be create a variable in template which store a filter name. something like this:
{% set filter_name = 'some_name' %}
{{ my_value|filter_name }}
But when I try this, I get an error:
TemplateAssertionError: no filter named 'filter_name'
Please help me to find a solution.
By doing {% set filter_name = 'some_name' %}
, you have create a string variable named "filter_name". You should create a filter which takes one more argument on basis of which it decides what to do.
{% set filter_name = 'some_name' %}
{{ my_value|myfilter(filter_name) }}
def myfilter(value, filtername):
if(filtername is 'twice')
return value*2
else
.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With