I have added function to controller class:
class ServiceHolder_Controller extends Page_Controller
{
public function RandomBackgroundNumber() {
return rand(1,4);
}
}
and the scheme below in template:
<% loop $Children %>
<a href="$Link" title="$Title" class="serviceBox <% if $First %>firstService<% end_if %>"
style="<% if $RandomBackgroundNumber == 1 %>
background-color: #19b5f0;
<% else_if $RandomBackgroundNumber == 2 %>
background-color: #00adef;
<% else_if $RandomBackgroundNumber == 3 %>
background-color: #59d1ff;
<% else_if $RandomBackgroundNumber == 4 %>
background-color: #14ade5;
<% end_if %> " >
<span style="display: block; text-align: center;">
<img src="$ServiceHolderIcon.URL" alt="$Title" style="max-width: 130px; max-height: 130px; margin: 0px; border: none; background: transparent;" />
</span>
<span style="display: block; text-align: center;">$Title</span>
</a>
<% end_loop %>
The loop is working nice, but I cannot set background this way... Could Anyone tell me why "style" attribute in my anchor is always empty?
EDITED
When I add additional else to the if-else statement I get the color but every anchor is the same blue color from "else" statement:
<% else %>
background-color: blue;
<% end_if %> " >
So it looks like the rand(1,4) do not return correct values to compare?