Best way to make a grouped foreach

2 views
Skip to first unread message

Guillaume

unread,
Aug 10, 2010, 5:52:44 AM8/10/10
to Spark View Engine Dev
Hi,

I was wondering what was the most elegant way to achieve this:
products is a list of X products, I want 2 products in each <li> like
that:

<ul>
<li>
Product1
Product2
</li>
<li>
Product3
Product4
</li>
<li>
Product5
</li>
</ul>

I did it with two <if>${"<li>"}</if> and conditions on productIndex/
productIsLast but it isn't very nice...

Guillaume

Igor Loginov (aka ilog2000)

unread,
Aug 10, 2010, 8:43:38 AM8/10/10
to Spark View Engine Dev
Hi,

If you need each second product in pair on a new line, I'd suggest 1)
to make ViewModel with a list of product pairs, and 2) to put nested
unordered lists. Like this:

<ul>
<for each='var productPair in productPairs'>
<li>
<ul>
<li>$!{productPair.Products[0]}</li>
<li>$!{productPair.Products[1]}</li>
</ul>
</li>
</for>
</ul>

Then set styles/classes as you like.
Reply all
Reply to author
Forward
0 new messages