From 7336b7af6c20a811930d49e97ef1bc447e062efa Mon Sep 17 00:00:00 2001 From: Ned Jackson Lovely Date: Mon, 12 Mar 2012 20:45:08 -0400 Subject: [PATCH] Fixes issue #77 by adding explanation to docs Points out that the Django empty is replaced by the Flask else. --- docs/switching.rst | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/switching.rst b/docs/switching.rst index ba3cfb1f..ee49df7e 100644 --- a/docs/switching.rst +++ b/docs/switching.rst @@ -177,9 +177,25 @@ operator. Here are some examples:: Loops ~~~~~ -For loops work very similar to Django, the only incompatibility is that in -Jinja2 the special variable for the loop context is called `loop` and not -`forloop` like in Django. +For loops work very similar to Django. Notably, in Jinja2 the special variable for +the loop context is called `loop` and not `forloop` like in Django. + +In addition, the Django `empty` argument is called `else` in Jinja2. For example, the +Django template:: + + {% for item in items %} + {{item}} + {% empty %} + No items! + {% endfor %} + +would be handled in Flask as:: + + {% for item in items %} + {{item}} + {% else %} + No items! + {% endfor %} Cycle ~~~~~ -- 2.47.2