By default
U-URL
H-html
X-XML
Trim-string. Strip ()
Entity-HTML Entity
Unicode-default Unicode string
Decode
N-cancel all default Filters
Multiple filters are separated by comma (,). You can also define a filter by yourself.
<%!DefMyescape (text ):Return "<Tag>"+ TEXT +"</Tag>"%>
Here's some tagged text :$ {"text" | myescape}
The custom filter must be a parameter that supports a string and return the filtered result.
Use expression_filter in the <% PAGE> label to use this filter for the entire page.
You can also set filter for block and def.
<%DefName ="Foo ()"Filter ="H, trim"> <B> ThisIsBold </B> </%Def>
In execution
$ {"Results"+ Somedef () +"More results"}
Will return (assuming somedef returns"Somedef's Results"String)
Somedef'S results more results
This is because somedef () is fully executed before the string link, the link string will get an empty string return value. To avoid this problem, Mako has two methods:
<%DefName ="Somedef ()"Buffered ="True">Somedef'S results</%Def>
The aboveCodeThe following code is generated:
DefSomedef (): context. push_buffer ()Try: Context. Write ("Somedef's results")Finally: Buf=Context. pop_buffer ()ReturnBuf. getvalue ()
Or use
$ {"Results"+ Capture (somedef) +"More results"}
Capture is similar to the python apply method. The parameter passed to somedef can be passed to somedef by capture.
In order to make def more flexible to filter, decorator also supports filter in template.
<% ! Def Bar (FN ): Def Decorate (context, * ARGs ,** KW): context. Write ( " Bar " ) FN ( * ARGs ,** KW) Context. Write ( " Bar " ) Return '' Return Decorate %> <% Def Name = " Foo () " Decorator = " Bar " > This Is Foo </% Def > $ {Foo ()}