How can I add different classes to html depending on how many fragments my page has?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I add different classes to html depending on how many fragments my page has?

johnnybigoode
Sorry for the verbose post, but I'm quite new to templating languages and Thymeleaf, so I think I might be doing something dumb in the process.

I'm doing this product catalog, and each product has its own page. And every product is grouped -according to some attributes- to 5 groups. Each group has a different color page. Each page has a bunch of sections, where every odd section is colored and every even section is just white. Kinda like this bootstrap demo https://blackrockdigital.github.io/startbootstrap-freelancer/

You can see that the portfolio and contact sections are white and the other sessions are green.

Here's the catch, not all products have all sessions. So I wanted to dynamically add the 'color' class to each odd section. My first approach was to create an colorObject with a getColor() method and add it to the attributes, and every time getColor() is called it would send a different class, being color for the colored sections and white for the white sections.

While I think this will solve my problem, I think I might me missing something here.

Any tips?
Reply | Threaded
Open this post in threaded view
|

Re: How can I add different classes to html depending on how many fragments my page has?

migueldeblas
Reply | Threaded
Open this post in threaded view
|

Re: How can I add different classes to html depending on how many fragments my page has?

johnnybigoode
Thank you! That's exactly what I was looking for