From: Fabien Potencier Date: Sun, 20 Nov 2011 09:20:20 +0000 (+0100) Subject: added a note about using the loop variable in a for condition X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f0e751aed9dcd3559c9cbaa327c4313f9efdf6b8;p=konrad%2Ftwig.git added a note about using the loop variable in a for condition --- diff --git a/doc/tags/for.rst b/doc/tags/for.rst index bbd5caf..6eed3b4 100644 --- a/doc/tags/for.rst +++ b/doc/tags/for.rst @@ -89,6 +89,14 @@ items. The following example skips all the users which are not active: The advantage is that the special loop variable will count correctly thus not counting the users not iterated over. +.. note:: + + Using the ``loop`` variable within the condition is not recommended as it + will probably not be doing what you expect it to. For instance, adding a + condition like ``loop.index > 4`` won't work as the index is only + incremented when the condition is true (so the condition will never + match). + If no iteration took place because the sequence was empty, you can render a replacement block by using ``else``: