I'm trying to a create Nav tree in Umbraco with Razor and struggling to figure this out. Any help would be appreciated
The content model will contain about 10 nodes in a 'for each loop' and for the first 3 nodes ONLY the first div class should be "item active" but after 3 nodes the div class should be "item"
What if you do something like this, did you get the output you want.
var leaderModels = Model.Content.AncestorOrSelf(1).DescendantsOrSelf("LeadershipLandingPage").OrderBy("leadershipSortorder"); foreach (var x in leaderModels.Take(12).InGroupsOf(3)){ if (x.IsFirst()){ <div class="**item active**"> <div class="row"> @foreach (var y in x){ <div></div> }
</div> </div> } else { <div class="**item**"> <div class="row"> @foreach (var y in x){ <div></div> } </div> } }
Finally....Yes that worked my friend! Thank you. While I am sure there is a more elegant way of doing this by not repeating the div in each loop this works perfect.
That is great that is works for you. Happy that I could help you to find a solution. Please remember to mark the topic as solved so others can go straight to the solution if they come across the same issue. You do this by clicking the little green tick on the post that give you the solution to your question / problem.
Looping over nodes in Groups in Razor
I'm trying to a create Nav tree in Umbraco with Razor and struggling to figure this out. Any help would be appreciated
The content model will contain about 10 nodes in a 'for each loop' and for the first 3 nodes ONLY the first div class should be "item active" but after 3 nodes the div class should be "item"
Hi ivansager,
Try somthing like this in your loop, ,first you need to tell your loop to take 10 nodes in a group of 3
hope this helps
I tried that but it does not work because it outputs the repearted Div row
I tried that but it does not work because it outputs the repearted Div row
Hi ivansager,
What if you do something like this, did you get the output you want.
Hope this helps,
/Dennis
Finally....Yes that worked my friend! Thank you. While I am sure there is a more elegant way of doing this by not repeating the div in each loop this works perfect.
Cheers
Ivan
Hi ivansager,
That is great that is works for you. Happy that I could help you to find a solution. Please remember to mark the topic as solved so others can go straight to the solution if they come across the same issue. You do this by clicking the little green tick on the post that give you the solution to your question / problem.
/Dennis
is working on a reply...