python - How to avoid repetitive filter specification in mako %def's? -
i find myself repeating same filter attribute on %def's in mako code:
<%def name="mydef1(a,b)" filter="trim"> # something </%def> ... <%def name="mydef2(b)" filter="trim"> # something </%def> is there way specify default set of filters %def's , avoid repetitive 'filter="trim"' in code?
i noticed there an option specify default filters expression filters, not find similar %def's.
there couple workarounds can use:
- you can use
default_filtersargument if okay importingdefsprogrammatically or loading them file. you can nest defs within parent def, , apply filtering parent def (i don't have mako on current machine, can't text this, 99% sure works, please call me out if wrong.)
<%def name="filterdefs()" filter="trim"> <%def name="mydef1(a,b)"> # something </%def> <%def name="mydef2(b)"> # something </%def> </def>finally, use
buffer_filterssuggested in comments. however, instead of addingbuffered="true"can calldefcapture(mydef)instead ofmydef()
Comments
Post a Comment