I made a 2Level-navigation - some 'chapters' don't have sub-chapters. When I click on the first Level of these chapters I want descend immediately to the FIRST SUB-chapter and show this page.
From what you are trying to accomplish if am not mistaken here is to be able to be redirected to the first child node from the first level itself if any child is visible ?
what you could do is change this line
<li><a href="@page.Url">@page.Name</a> to
var subUrl = (page.Children.Count()>0) ? page.Children.First().Url:page.Url; <li><a href="@subUrl"">@page.Name</a>
I have make the same on one of my solutions. And the way I did was by using the UmbracoRedirect.
So go to your setttings section, then under Document Types, Find the document type witch contains the fields for your menu. On there add a new property with the alias UmbracoRedirect, and the data type should be content picker.
So choose the page in the content section that you want to redirect, Pick the new page in content picker with the alias UmbracoRedirect.
@Fuji: It works, but I also have items in level 1 without children, when I now click on them I get an error. So I just want to redirect to the first child node if there ARE children. Do you understand?:)
Weird this should work, so whenever Level 1 node has child it should display the first url and if not the level 1 url itself . Can you double Check if they are visible ?
var subUrl =(page.Children.Count()>0)? page.Children.First().Url:page.Url;
prevent click on navi-item if child-item
Hi
I made a 2Level-navigation - some 'chapters' don't have sub-chapters. When I click on the first Level of these chapters I want descend immediately to the FIRST SUB-chapter and show this page.
My code till now:
<ul class="mainMenu level1">
@foreach(var page in Model.AncestorOrSelf(1).Children.Where("Visible"))
{
<li><a href="@page.Url">@page.Name</a>
@if(page.Children.Where("Visible").Count() > 0)
{
<ul class="level2">
@foreach(var subpage in page.Children.Where("Visible"))
{
if(@subpage.Where("NodeTypeAlias!= \"Sponsor\"")){
<li><a href="@subpage.Url">@subpage.Name</a></li>
}
}
</ul>
}
</li>
}
</ul>
I hope sb can help me, it's important because this website is my final paper for my bachelor's degree in Multimedia Writing.
Thank you,
Kristina
Hi Kristina,
From what you are trying to accomplish if am not mistaken here is to be able to be redirected to the first child node from the first level itself if any child is visible ?
what you could do is change this line
Hi Kristina,
I have make the same on one of my solutions. And the way I did was by using the UmbracoRedirect.
So go to your setttings section, then under Document Types, Find the document type witch contains the fields for your menu. On there add a new property with the alias UmbracoRedirect, and the data type should be content picker.
So choose the page in the content section that you want to redirect, Pick the new page in content picker with the alias UmbracoRedirect.
http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracoredirect
I have made to sreenshots to illustrate.
I donĀ“t know if it is best practice, but I hope it can helps you.
/Dennis
@Fuji: It works, but I also have items in level 1 without children, when I now click on them I get an error. So I just want to redirect to the first child node if there ARE children. Do you understand?:)
Thanks
Kristina
@Dennis: Thanks but it's a bit to complicate :)
Hi Kristina,
Weird this should work, so whenever Level 1 node has child it should display the first url and if not the level 1 url itself . Can you double Check if they are visible ?
Aaah yes, in fact all level1 have children, but some are hidden in navigation.
So I tried like this:
var subUrl = (page.Children.Count()>0 && page.Children.Where("Visible"))? page.Children.First().Url:page.Url;
but the && doesn't work, I know that from PHP, how do I write it right?
Try this instead
It works!
Thanks a lot!
Kristina
Great !!! :)
is working on a reply...