Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does python mako template support connitue/break in loop context?

Is it possible to use continue/break in a %control structure loop.

For example:

% for x in range(1):
 % continue
% endfor

Thanks,

like image 408
kerwin Avatar asked Jun 16 '12 02:06

kerwin


People also ask

What is Mako in Python?

Mako is a template library written in Python. Mako is an embedded Python (i.e. Python Server Page) language, which refines the familiar ideas of componentized layout and inheritance. The Mako template is used by Reddit. It is the default template language included with the Pylons and Pyramid web frameworks.

How do you comment in Mako?

Comments. Comments come in two varieties. The single line comment uses ## as the first non-space characters on a line: ## this is a comment. ...text ...


1 Answers

Yes. You use <% continue %> and <% break %>.

Example:

from mako.template import Template 
t = Template( 
""" 
% for i in xrange(5): 
    % if i == 3: 
        <% break %> 
    % endif 
    ${i} 
% endfor 
% for i in xrange(5): 
    % if i == 3: 
        <% continue %> 
    % endif 
    ${i} 
% endfor 
""") 
print t.render() 

Output:

0 
1 
2 
0 
1 
2 
4 
like image 162
shihongzhi Avatar answered Sep 23 '22 17:09

shihongzhi