Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine template filter django

In my template, I use multiple filters as below :

story|force_escape|markdown|nlToBr

I use this flow of filter many times in my page and I would like to create a filter that use those three filters. Is there a way to do eat easily or do I have to find the code of each filter and copy paste back to back in on single custom filter ?

Thank you very much ! Dorian

like image 256
Dorian Amouroux Avatar asked Mar 23 '26 06:03

Dorian Amouroux


1 Answers

Filters are just functions; you can call them inside your own filter.

from ... import ...

@register.filter
def combo(value):
    return force_escape(markdown(nlToBr(value)))
like image 94
Daniel Roseman Avatar answered Mar 24 '26 23:03

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!