Allow control statements (if, else, endif, etc.) to be closed so they can be inlined

Issue #218 new
created an issue

In line with the discussion here:

The pertinent parts quoted:

However, if the case is that Jinja2's (% if <expr> %}, because it has a 
closing %} allows it to be inlined like {% if <expr> %} <html> {% else %} 
<html> {% endif %}, then I'd want to think a bit bigger here.   I'd want to 
go into match_control_line() as we did and just find some way to make the 
newline optional:

% if <expr>:\n
% else:\n
% endif\n

we could perhaps just co-opt the { } verbosity:

{% if <expr>:}  <html> {% else:} <html> {% endif}

or just rip them off totally:

{% if <expr> %}  <html> {% else %} <html> {% endif %}

either of the above would require a rewritten (either in-place or additional 
version of) match_control_line(), as we'd be doing the same kind of matching 
which we do in match_expression(), which is that we need to make use of 
parse_until_text() so that we properly skip over anything that might be 
Python code.     I'd want the two formats to be completely interchangeable:

% if expr:
<html> {% else %} <html> 
% endif

{% if <expr> %} <html>
% elif <expr>:
% else:
<html> {% endif %}

just some ideas but I'd need someone to be motivated to help patch out and add new tests as well.

I've frequently used Python's native {{{1 if 1 else 0}}} syntax, but it doesn't always seem ideal.

This is the only thing I can think of that other template languages can do that I wish Mako had.

Thank you for making Mako.

Comments (2)

  1. Log in to comment