From 8ebbaaa4cc6197a96014681f2b7dd9bddd477585 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Sun, 17 Mar 2013 23:18:20 -0700 Subject: [PATCH] Adding a section about the slice filter This code example shows how to loop over a subset of values in order to implement one common use-case of "break" in PHP. I decided to use the "full" notation of slice rather than the sugared version (that example would just be "for user in users[:10]") --- doc/tags/for.rst | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/doc/tags/for.rst b/doc/tags/for.rst index 722861a..e39a59b 100644 --- a/doc/tags/for.rst +++ b/doc/tags/for.rst @@ -155,3 +155,17 @@ You can also access both keys and values:
  • {{ key }}: {{ user.username|e }}
  • {% endfor %} + +Iterating over Subset +--------------------- + +You might want to iterate over a subset of values. This can be achieved using the ``slice`` filter: + +.. code-block:: jinja + +

    Top Ten Members

    + -- 1.7.2.5