Skip to content
This repository

Minor doc fixes. #69

Closed
wants to merge 1 commit into from

3 participants

Christoph Zwerschke Ron DuPlain Ned Jackson Lovely
Christoph Zwerschke

No description provided.

Ron DuPlain
Collaborator

Note that the else part works differently in ordinary Python where it
is executed when a break happened, which is not possible here.

@mitsuhiko Can you confirm this? If true, will pull.

Ned Jackson Lovely
njl commented March 12, 2012

This is not the case.

http://docs.python.org/tutorial/controlflow.html

"Loop statements may have an else clause; it is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement."

Ron DuPlain rduplain closed this March 13, 2012
Ron DuPlain
Collaborator

I pulled in the typo fixes, now a21f2ed. Thanks.

Christoph Zwerschke
Cito commented March 21, 2012

Sorry, in that note above I wanted to say "where it is executed when a break did not happen", not "where it is executed when a break happened", so it is good that you didn't pull it.

But the main point here that the for statement behaves differently from ordinary Python is still correct and should still be mentioned. In ordinary Python, the else part would always be executed when there is no break, while in Jinja it is only executed when no iteration took place. Since in Jinja breaks are not possible, the else part would be always executed, so it makes sense that the behavior was changed. However, readers should be made aware of that different behavior.

Ron DuPlain
Collaborator

Thanks for following up. The documentation currently reads:

"If no iteration took place because the sequence was empty or the filtering removed all the items from the sequence you can render a replacement block by using else:"

Is this not enough?

Christoph Zwerschke
Cito commented March 21, 2012

There's nothing wrong with the documentation.

I just think it deserves special mention when the behavior is different from ordinary Python, because you usually expect Jinja2 keywords to operate in the same way as the corresponding Python keywords. However, this is not the case for else. For instance, the Jinja2 template

{% for i in range(3) %} {{i}} {% else %} nothing {% endfor %}

will just output "0 1 2" while the Python code

for i in range (3): print i,
else: print "nothing"

will output "0 1 2 nothing".

Ron DuPlain
Collaborator

I'll find a place for this, unless you'd like to submit another pull request.

Christoph Zwerschke
Cito commented March 21, 2012

Ok, this is now pull request #112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 23, 2011
Christoph Zwerschke Fix typos and one small addition to the docs. 0fd99c1
This page is out of date. Refresh to see the latest.
7  docs/templates.rst
Source Rendered
@@ -332,7 +332,7 @@ advantage of it, see :ref:`null-master-fallback`.
332 332
 
333 333
 The filename of the template depends on the template loader.  For example the
334 334
 :class:`FileSystemLoader` allows you to access other templates by giving the
335  
-filename.  You can access templates in subdirectories with an slash::
  335
+filename.  You can access templates in subdirectories with a slash::
336 336
 
337 337
     {% extends "layout/default.html" %}
338 338
 
@@ -571,6 +571,9 @@ by using `else`::
571 571
     {% endfor %}
572 572
     </ul>
573 573
 
  574
+Note that the `else` part works differently in ordinary Python where it
  575
+is executed when a `break` happened, which is not possible here.
  576
+
574 577
 It is also possible to use loops recursively.  This is useful if you are
575 578
 dealing with recursive data such as sitemaps.  To use loops recursively you
576 579
 basically have to add the `recursive` modifier to the loop definition and
@@ -819,7 +822,7 @@ Jinja2 supports putting often used code into macros.  These macros can go into
819 822
 different templates and get imported from there.  This works similar to the
820 823
 import statements in Python.  It's important to know that imports are cached
821 824
 and imported templates don't have access to the current template variables,
822  
-just the globals by defualt.  For more details about context behavior of
  825
+just the globals by default.  For more details about context behavior of
823 826
 imports and includes see :ref:`import-visibility`.
824 827
 
825 828
 There are two ways to import templates.  You can import the complete template
2  jinja2/filters.py
@@ -557,7 +557,7 @@ def do_batch(value, linecount, fill_with=None):
557 557
     A filter that batches items. It works pretty much like `slice`
558 558
     just the other way round. It returns a list of lists with the
559 559
     given number of items. If you provide a second parameter this
560  
-    is used to fill missing items. See this example:
  560
+    is used to fill up missing items. See this example:
561 561
 
562 562
     .. sourcecode:: html+jinja
563 563
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.