Empty lines in generated files

44 views
Skip to first unread message

Paul Baumer

unread,
Nov 23, 2017, 9:41:50 AM11/23/17
to Mako Templates for Python
Hello,

I have a simple template which looks like:

% if context.bookId:
bookid: ${content.bookId}
% endif

the generated file includes 3 lines instead of (expected) 1. Hence it looks like

<empty line>
bookid: 33
<empty line>

How can I get rid of the empty lines?

Thanks,

Paul

Mike Bayer

unread,
Nov 24, 2017, 5:25:38 PM11/24/17
to mako-d...@googlegroups.com
you can put a backslash at the end of a line to suppress trailing whitespace:

http://docs.makotemplates.org/en/latest/syntax.html#newline-filters

t = Template(r"""
<foo>\
% if True:
hi there\
% endif
</foo>
""")

print t.render()
> --
> You received this message because you are subscribed to the Google Groups
> "Mako Templates for Python" group.
> To unsubscribe from this group and stop receiving emails from it, 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.
Reply all
Reply to author
Forward
0 new messages