Best way to escape MAKO template itself

686 views
Skip to first unread message

Jinghui Niu

unread,
Feb 24, 2016, 9:01:28 PM2/24/16
to Mako Templates for Python
Hi, I want to have a <%def> that render a mako template. I learned from the documentation that Mako allows you to escape html, url, etc., but how can I tell mako not to interpret those <%! symbols and renders it as it is? Is there a switch that I can kind of turn on and off for this? Thanks.

Jonathan Vanasco

unread,
Feb 25, 2016, 2:25:56 PM2/25/16
to Mako Templates for Python
http://docs.makotemplates.org/en/latest/syntax.html#expression-escaping

The % sign can also be “escaped”, if you actually want to emit a percent sign as the first non whitespace character on a line, by escaping it as in %%:

Jonathan Vanasco

unread,
Feb 25, 2016, 3:17:07 PM2/25/16
to Mako Templates for Python
I just realized that might not work for tags.

I suggest using two percent-signs on tags though, then filtering the output to replace occurrences of `<%%` and `</%%` with `<%` and `</%`.  That will probably get you your result fastest, and not involve many edge cases.

binadam

unread,
Feb 26, 2016, 1:41:31 PM2/26/16
to Mako Templates for Python
I'm sure I'm misunderstanding the question: why can't you use the <%text> tag?

Jinghui Niu

unread,
Feb 26, 2016, 1:45:15 PM2/26/16
to mako-d...@googlegroups.com

I'm not aware of that tag, sorry. Is it in the documentation? Thank you for the clue!

On Feb 26, 2016 10:41 AM, "binadam" <ibna...@gmail.com> wrote:
I'm sure I'm misunderstanding the question: why can't you use the <%text> tag?

--
You received this message because you are subscribed to a topic in the Google Groups "Mako Templates for Python" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mako-discuss/Myl-pHF8izs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mako-discuss...@googlegroups.com.
To post to this group, send email to mako-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/mako-discuss.
For more options, visit https://groups.google.com/d/optout.

binadam

unread,
Feb 26, 2016, 1:55:43 PM2/26/16
to Mako Templates for Python

Jinghui Niu

unread,
Feb 26, 2016, 1:57:46 PM2/26/16
to mako-d...@googlegroups.com
Ah ha! That's exactly what I was looking for! I was focusing on the wrong part and studied quite a lot on escaping. Thanks.
Reply all
Reply to author
Forward
0 new messages