-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'loop.parity' for zebra row coloring #26
Comments
Oops, found |even and |odd only now. :) So, without the patch one could write something like: <tr class="{{ loop.index|even ? 'even' : 'odd' }}"> Not as nice as the suggestion, but quite ok still. |
cycle node support would be nice too. |
added the cycle filter (closed by 075f541) |
Great work! The cycle seems far better than the patch I suggested. |
Fabien, can you make
|
If I do that, on which variable should I cycle? A global variable? If so, then depending on what you have on the page before, it won't always start at the same element. |
Static variable inside Twig_Node_Cycle?
Does cycle tag can get access to name of variable name |
That's not possible. But even if it was, it means that the cycle is not predictable. |
This new feature is really great and makes many common and troubleful tasks a piece of cake ;) Thanks a lot for adding it! However with django you can do: it seems that django cycles on the current iteration index variable (I have no idea about how django cycle beahves with nested iterations)... I don't know how django implemented it (and how twig architecture is similiar to django template system) but its approch sometimes could be more readable and easier to use. |
In Django, there is no state for the cycle tag, which means that you cannot tell which will be the first value used in a loop. To me, this is not a good thing. |
That said, that's quite easy to implement a cycle tag like the one in Django. |
So, with django, if you do something like this: On the other way, using the current twig cycle implementation, i'd like to know what could be the best way to use cycle inside a "foreach" loop. Maybe: ... a little bit tricky for designers |
Hello,
it's very common that one wants to color even and odd rows of a list/table/etc. with alternative colors. That's why I'm suggesting a shortcut variable 'loop.parity' that yields 'even' or 'odd'. It could be used like this:
Very readable, and it also makes the css code more readable.
Here's a patch:
The text was updated successfully, but these errors were encountered: