odd/even element in list model

42 views
Skip to first unread message

Giulio Fior

unread,
Aug 6, 2013, 5:36:54 AM8/6/13
to ent...@googlegroups.com
Hi all,
I'm trying to create a list model in which odd elements has a different html code

odd element
<li><img src="$content.icon.getImagePath("0")">

even element
<img src="$content.icon.getImagePath("0")"></li>

is this possible?

William Ghelfi

unread,
Aug 6, 2013, 5:45:17 AM8/6/13
to ent...@googlegroups.com
I dont' think it's possible using only Velocity :-/ 

http://velocity.apache.org/engine/devel/vtl-reference-guide.html

You could try with custom Java code, but that is beyond my ability to help someone (I'm not a Java programmer)


--
--
_________________________________________________________________________
Entando Group
ent...@googlegroups.com
http://groups.google.com/group/entando/
_________________________________________________________________________
 
Follow us on:
Twitter http://twitter.com/EntandoSrl/
Facebook https://www.facebook.com/pages/Entando/140204982772024?fref=ts
Linkedin http://www.linkedin.com/groups?gid=2570784&trk=hb_side_g
Slideshare http://www.slideshare.net/entandosrl
---
You received this message because you are subscribed to the Google Groups "Entando" group.
To unsubscribe from this group and stop receiving emails from it, send an email to entando+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

William Ghelfi
Director of Research
entando Team

Direct: Italy +39 070 24 00 53
Twitter: @trumbitta | Skype: wiz_of_id | GitHub: trumbitta
Company: http://www.entando.com | Community: http://www.entando.org
Follow us! Twitter@entandosrl | Facebook/entando | Linkedin | Youtube

Marco Bolzan

unread,
Aug 6, 2013, 6:07:50 AM8/6/13
to ent...@googlegroups.com
or you can use VTL, since in the loop velocityCount is the current index:
# if($velocityCount % 2 == 0) .. is an even line

http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html

//bolzan

2013/8/6 William Ghelfi <w.gh...@entando.com>

Andrea L. Dessì

unread,
Aug 6, 2013, 6:08:05 AM8/6/13
to ent...@googlegroups.com
Hi,

you can try doing something like this using the modulo operation with $velocityCount

<ul>
#foreach( $product in $allProducts )
   $set ($even = $velocityCount % 2)
   <li> even: $even | $product</li>
#end
</ul>



--
Andrea

Andrea L. Dessì

unread,
Aug 6, 2013, 6:09:09 AM8/6/13
to ent...@googlegroups.com
Oh yes :) the same like Marco just suggested

--
Andrea

Giulio Fior

unread,
Aug 6, 2013, 6:15:49 AM8/6/13
to ent...@googlegroups.com, andrealuc...@gmail.com
In a list model there's no #foreach loop, $velocityCount  is always = 1.

I think I need some java code.

Andrea L. Dessì

unread,
Aug 9, 2013, 3:15:46 AM8/9/13
to ent...@googlegroups.com
Giulio if you are using the "content list" widget so you have to think different at the problem :)

We know the list is generated from the jsp content_viewer_list.jsp 
so there's a <c:forEach> there. Maybe you can customize it.

Another way could be the use CSS3 with the :nth-child selector.
However this is not supported by some old browsers.

Let us know how you'll handle that ;)

--
Andrea


On Tue, Aug 6, 2013 at 12:15 PM, Giulio Fior <giuli...@archeometra.it> wrote:
In a list model there's no #foreach loop, $velocityCount  is always = 1.

I think I need some java code.



--
Andrea

Reply all
Reply to author
Forward
0 new messages