I find myself repeating the same filter attribute over all the %def's in my mako code:
<%def name="mydef1(a,b)" filter="trim">
# something something something
</%def>
...
<%def name="mydef2(b)" filter="trim">
# something something something
</%def>
Is there a way to specify a default set of filters for all %def's and avoid the repetitive 'filter="trim"' in my code?
I noticed there is an option to specify default filters for expression filters, but i could not find something similar for %def's.
There are a couple workarounds you can use:
default_filters
argument if you are okay
importing the defs
programmatically or by loading them from
a file.You can nest the defs within a parent def, and apply the filtering to the parent def (I don't have mako on my current machine, so I can't text this, but I am 99% sure this works, please call me out if I am wrong.)
<%def name="filterdefs()" filter="trim">
<%def name="mydef1(a,b)">
# something something something
</%def>
<%def name="mydef2(b)">
# something something something
</%def>
</def>
Finally, you could use buffer_filters
as suggested in the
comments. However, instead of adding buffered="True"
you can just
call the def
with capture(myDef)
instead of myDef()
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