So if there are any children then the "menu-item-has-children" class will be set otherwise the "menu-item" class will be set. If you don't wish to add a clash you can just leave it empty or maybe even just use null. Not sure about that one though...still new at this way of thinking when rendering things :)
Inline is the way to go when using Razor syntax...I liked the xslt way of doing it much more though :)
Any subpages then add-class Partial view
Hi Guys
Still in a lot of questions of doing the Razor :P
I would like to check for "Children.Any" and if there are any then add a class of "menu-item-has-children".
I'm really not sure if the inline script is the right way to do it?
I just know that it's possible to add like class attributes in XSLT? so whats the best way to do it in Partials/razor :D
Hi Mads
Perhaps you can use topPage.Children.Count() instead? The count will return the number of existing children so it will be 0,1,2 etc.
So this should work
So if there are any children then the "menu-item-has-children" class will be set otherwise the "menu-item" class will be set. If you don't wish to add a clash you can just leave it empty or maybe even just use null. Not sure about that one though...still new at this way of thinking when rendering things :)
Inline is the way to go when using Razor syntax...I liked the xslt way of doing it much more though :)
Hope this helps and works.
/Jan
Hi Jan
Great reply - it makes totaly sense - But yeah the XSLT way I kind of like better to :)
Bottomline is that the code works but it really is messy to look at if you have, like me, diffrent "if's" at the same element :P
It looks like this for the moment:
<li class="@(topPage.IsAncestorOrSelf(CurrentPage) ? "current" : null) @(topPage.Children.Where("TemplateId != 0 && Visible").Count() > 0 ? "menu-item-has-children" : "menu-item")">
Hi Mads
Thanks, you're welcome :)
Yup, it's really ugly to look at - it makes my eyes bleed.
You can probably save some of the expressions in variables making it look a tad nicer but even though you do that it will stille be a bit ugly.
But I'm thinking you should be able to save the count into a var like
And then in your test just check numbersOfChildren > 0 for instance
/Jan
is working on a reply...