From: Fabien Potencier Date: Sun, 28 Nov 2010 16:14:00 +0000 (+0100) Subject: made some small changes to the previous commit X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=15e6682421b72b5100d379bab2e675aeb20d5df5;p=web%2Fkonrad%2Ftwig.git made some small changes to the previous commit --- diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index 91880c2..5797df3 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -582,18 +582,18 @@ You can also access both keys and values: >keys and values (`{% for key, value in users|items %}`). To conveniently display comma-separated lists or things alike, you can use -`joined by ", "` at the end of the loop statement. Of course this is not -limited to commas. +`joined by ", "` at the end of the loop statement (as of Twig 0.9.10). Of +course this is not limited to commas: [twig]

Members

-

- {% for key in users|keys joined by ", " %}{{ key }}{% endfor %} -

+

{% for user in users joined by ", " %}{{ user }}{% endfor %}

+ + {# generates a string like

Fabien, Jordi, Thomas, Lucas

#} >**NOTE** ->This way you don't have to check if the item is the first or last, the comma ->will only be added in between two items. +>This way you don't have to check if the item is the last one, the comma will +>only be added in between two items. ### If diff --git a/test/Twig/Tests/Fixtures/tags/for/joined_by.test b/test/Twig/Tests/Fixtures/tags/for/joined_by.test new file mode 100644 index 0000000..69b087b --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/for/joined_by.test @@ -0,0 +1,8 @@ +--TEST-- +"for" tag support the "joined by" clause +--TEMPLATE-- +{% for item in items joined by ', ' %}{{ item }}{% endfor %} +--DATA-- +return array('items' => array('a', 'b', 'c')) +--EXPECT-- +a, b, c