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:

  1. you can use default_filters argument if okay importing defs programmatically or loading them file.
  2. 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> 
  3. finally, use buffer_filters suggested in comments. however, instead of adding buffered="true" can call def capture(mydef) instead of mydef()


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -