I'm trying to output a lexicon/glossary, and have some problems grouping the output according to first letters.
The lexicon items are DataObjects attached to all pages. In the Page_Controller they are collected
function LexiconAllAggregator() {
$LexiconSet = DataObject::get(
"Lexicon",
"`PageID` IN (" . implode(",", $all_lexicon) . ")",
"Term ASC",
"",
""
);
return $LexiconSet ;
}
and output in the template
<% control LexiconAllAggregator %>
<h3><a href="{$Top.Link}lexikon/$ID">$Term</a></h3>
<p>$Explanation.FirstParagraph</p>
<% end_control %>
Now i want to group them, ie to have divs (with all first letters) after first letter of the terms change. So a new property $Break for $LexiconSet is needed which is should be calculated in the Page_Controller and checked in the template:
<% control LexiconAllAggregator %>
<% if Break %> <div> A B C ... </div> <% end_if %>
<h3><a href="{$Top.Link}lexikon/$ID">$Term</a></h3>
<p>$Explanation.FirstParagraph</p>
<% end_control %>
But I just don't get it how it has to be done to get a new property into the DataObjectSet
I think it will start with something like that
$LexiconSetNew = new DataObjectSet();
foreach ( $LexiconSet as $LexiconSetSingle ) {
//??????
}
Thanks in advance.