3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 736 Views |
-
Counter on control loop with group by

11 October 2011 at 12:51am Last edited: 23 July 2012 2:59pm
I'm new to Silverstripe. I am bit struggling with its templating scheme.
Basically this code:
<% control Page %>
<% control Children.GroupBy(Category) %>
$PageName . " - cat " . $Category . " - " . $Counter
<% end_control %>
<% end_control %>If we have 6 page, 2 category (3 each). Then with function $Counter { return $this->iteratorPos } on page controller. Above code will ouput:
Page 1 - cat 1 - 1
Page 2 - cat 1 - 2
Page 3 - cat 1 - 3
Page 4 - cat 2 - 1
Page 5 - cat 2 - 2
Page 6 - cat 2 - 3The counter takes into account the 'Group By' on control. Is there anyway to bypass this?
I would like a counter that returns 1 to 6 instead.
Thanks in advance.
-
Re: Counter on control loop with group by

11 October 2011 at 6:40am
Hi there
Normally you wouldn't have to <% control Page %>, as you're already on the page...
Also the functiondescription says that the GroupBy(Category) will return 2 separate DataObjectSets - 1 for each Category, and I guess IteratorPos can only return the objects position within the DataObjectSet that is currently looped.
If it's only about sorting the Childpages by category you could do something like (simplyfied, needs errorhandling, in your page controler):
function MyChildren() {
$children = $this->Children();
$children->sort('Category');
return $children;
}and then
<% control MyChildren %>
$Pos - $Title - cat: $Category<br />
<% end_control %>
| 736 Views | ||
|
Page:
1
|
Go to Top |

