Best way to produce alternating table row styles when iterating through collection?

191 views
Skip to first unread message

Chris Schnyder

unread,
Mar 23, 2012, 12:06:30 PM3/23/12
to dotl...@googlegroups.com
I'm using Dot Liquid to generate HTML email.  I'm creating tabular data within the email and need to apply some alternate-row styling to increase readability.  Being that this is going to be rendered in a wide variety of email clients, I can't rely on CSS to make this happen, consistently.  I'd like to change the row markup conditionally based on whether the current items index in the collection is odd or even.  Does Dot Liquid provide a way for a template designer to access that information?

Alessandro Petrelli

unread,
Mar 23, 2012, 12:09:30 PM3/23/12
to dotl...@googlegroups.com
This example should help, you just need to pass to cycle the two markup
{% for post in site.categories.articles %}
   <article class="{% cycle 'odd', 'even' %}"></article>
{% endfor %}

AP

Chris Schnyder

unread,
Mar 23, 2012, 12:14:14 PM3/23/12
to dotl...@googlegroups.com
Perfect, Thank you!  Solved in under 5 minutes -- you rock!


On Friday, March 23, 2012 11:09:30 AM UTC-5, Alessandro Petrelli wrote:
This example should help, you just need to pass to cycle the two markup
{% for post in site.categories.articles %}
   <article class="{% cycle 'odd', 'even' %}"></article>
{% endfor %}

AP


Reply all
Reply to author
Forward
0 new messages