Search code examples
mako

Escape '##' in Mako templates and not have it interpreted like a comment


I have this file

## Hello

% for i in range(2):
 ${i}
% endfor

When I run mako-render I get:

0
1

But I want:

## Hello

0
1

But I don't know how to escape ## and have Mako not interpret it as a comment. Is it possible?


Solution

  • According to a previous mailing list post, there’s no way to escape line comments.

    You can use a <%text> block:

    <%text>
    ## Hello
    </%text>
    

    or an expression substitution:

    ${"##"} Hello