Error in Mako: "expected %>", escaping %

I'm currently writing Javascript in a mako file, and on one line, I have to check whether two strings are equal. The string I'm checking against has "<%text" within it, so I used to get an error saying there's no tag named text. I escaped that by adding a second % to get "<%%text". But now, I'm getting the following error.

SyntaxException: Expected: %> in file file.mako

What is the problem?


ANSWERS:


"<%" and "%>" are reserved symbols in Mako. If they appear in your template, Mako will assume that you mean to escape a python code block. Here is an example of what I mean:

"""
<%
  some_var = 'foo'
  other_var = '{0} bar'.format(some_var)
%>
"""

Take a look at for more details

Excuse the quotes, "<%" and "%>" are also reserved symbols in the Stack Overflow WYSIWYG editor.

If the Javascript variables you are comparing contain reserved symbols, you will have to find another way of comparing them. Perhaps you could use the unicode entity for the percent sign:

For example:

if ('<%' == '<\u0025') {
    alert('success!');
}


 MORE:


 ? What's the difference between using <%def%> and <%include%> in mako?
 ? Mako template filter ordering
 ? Check if %def is empy in mako template
 ? Alternative mobile templates for a mako+flask-django app
 ? Trying to use Mako template in python to render json data
 ? Trying to use Mako template in python to render json data
 ? Trying to use Mako template in python to render json data
 ? Blank page through Mako template rendering in python / cherrypy
 ? How do I import a local module in a Mako template?
 ? Url for the current page from a Mako template in Pylons