3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 800 Views |
-
Counting rows in template language

14 March 2010 at 3:44pm Last edited: 14 March 2010 3:46pm
Hi,
I need some way to create x many objects add a clearing class and add another create x many objects add another clearing class and continue. Example = thumbnails of photos in a gallery. Yes i could use a table but I would run into the same problem. The kind of functionality I'm looking for is similar to Even and Odd, but not with a base of 2.
In php i would do something like:
$j =0;
for ($i =0; $i < $total; $i++) {
echo $something;
$j++;
if($j == 5) {
echo '<div class="clear"> </div>';
$j=0;
}
}What I've done is added the below code to ViewableData:
/*
* Return if we have a complete row or not
* @param int $denominator, which defaults to 1.
* @return boolean
*/
function IsDivisibleBy($denominator = 1) {
if (is_int(($this->iteratorPos+1) / $denominator)) {
return true;
} else {
return false;
}
}I can then use the below in my template class:
<% if IsDivisibleBy(3) %>Is there a better way?
-
Re: Counting rows in template language

14 March 2010 at 7:54pm
2.4 added a modulus factor into ViewableData. The change was applied here: http://open.silverstripe.org/changeset/95584
You could probably use something like that. It uses modulus in PHP (%) to do what you're looking for.
Sean
| 800 Views | ||
|
Page:
1
|
Go to Top |


