this feels straight forward enough, but obviously, i am missing the point.
My client has 'Classes' that occur at different times, have different course numbers, but the NAMES are the same - let's call it pageHeading... how would i create a list of all classes, but only show each pageHeading ONCE if they are duplicated?
i thought this would work.. but no joy
@{ // Get root node: var root = Model.AncestorOrSelf(); // Get all descendants, filter by type: var nodes = root.Descendants("Class"); // Loop through the filtered nodes, displaying the properties: <ul> @foreach (var node in nodes.GroupBy("@node.pageHeading")) { <li> @node.pageHeading </li> } </ul> }
It has EventOverview which groups on the property EventType, seems similar to what you're doing. As soon as you have a grouping you have to do another foreach in that, the example is:
<h2>Event Calendar Grouped By Event Type</h2>
@{
var eventsByType = Model.Children.GroupBy("EventType");
foreach (var eventGroup in eventsByType)
{
<h3>@library.GetPreValueAsString(eventGroup.Key)</h3>
foreach (var node in Model.Children.Where("EventType == " + eventGroup.Key).OrderBy("EventDateTime"))
{
<span>NodeName: @node.Name (Node Id: @node.Id)</span><br />
}
}
}
okay, so the Key thing is what i did not understand... i thought that was a docType property you were referencing... all good now... thanks Sebastiaan!
simple groupBy based on page property?
this feels straight forward enough, but obviously, i am missing the point.
My client has 'Classes' that occur at different times, have different course numbers, but the NAMES are the same - let's call it pageHeading... how would i create a list of all classes, but only show each pageHeading ONCE if they are duplicated?
i thought this would work.. but no joy
using umbraco 4.8
thanks!
First of all, your foreach should be:
Check out my Razor examples package: http://our.umbraco.org/projects/developer-tools/cultiv-razor-examples
It has EventOverview which groups on the property EventType, seems similar to what you're doing. As soon as you have a grouping you have to do another foreach in that, the example is:
wow, i must be thick -- but i cannot get this to work at all... feels like it should be simple.
my node structure looks like this...
Calendar home
- semester folder [really just a placeholder]
- - Course ID# [pageHeading of Unit 1]
- - Course ID# [pageHeading of Unit 2]
- - Course ID# [pageHeading of Unit 1]
- semester folder
- - Course ID# [pageHeading of Unit 1]
so, what i need is Unit 1 to only show in the list ONCE, but to show all unique courses below the calendar home.
does that make sense?
The property pageHeading has the value of "Unit 1" or "Unit 2"?
On the semester folder add this: (let's start with just Children, I know that works, not sure about Descendants):
For Descendants it should be something like:
okay, so the Key thing is what i did not understand... i thought that was a docType property you were referencing... all good now... thanks Sebastiaan!
is working on a reply...