Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged branch beryllium/patch-1 (PR #1032)

This PR was merged into the master branch.

Discussion
----------

Adding a section about the slice filter to doc/tags/for.rst

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]")

Commits
-------

202641a Adding link to slice filter per Stof's suggestion
8ebbaaa Adding a section about the slice filter
  • Loading branch information...
commit 34b03285ad2eb5b2469302e43842419acddb46a5 2 parents 2f14935 + 202641a
Fabien Potencier authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 doc/tags/for.rst
14 doc/tags/for.rst
View
@@ -155,3 +155,17 @@ You can also access both keys and values:
<li>{{ key }}: {{ user.username|e }}</li>
{% endfor %}
</ul>
+
+Iterating over Subset
+---------------------
+
+You might want to iterate over a subset of values. This can be achieved using the :doc:`slice<../filters/slice>` filter:
+
+.. code-block:: jinja
+
+ <h1>Top Ten Members</h1>
+ <ul>
+ {% for user in users|slice(0,10) %}
+ <li>{{ user.username|e }}</li>
+ {% endfor %}
+ </ul>
Please sign in to comment.
Something went wrong with that request. Please try again.