Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kristina 33 posts 49 karma points
    Apr 18, 2013 @ 10:57
    Kristina
    0

    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><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><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

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 18, 2013 @ 11:11
    Fuji Kusaka
    0

    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

     <li><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>
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2013 @ 11:24
    Dennis Aaen
    0

    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

  • Kristina 33 posts 49 karma points
    Apr 18, 2013 @ 14:33
    Kristina
    0

    @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

  • Kristina 33 posts 49 karma points
    Apr 18, 2013 @ 14:35
    Kristina
    0

    @Dennis: Thanks but it's a bit to complicate :)

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 18, 2013 @ 20:33
    Fuji Kusaka
    0

    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 ?

    var subUrl =(page.Children.Count()>0)? page.Children.First().Url:page.Url;
  • Kristina 33 posts 49 karma points
    Apr 19, 2013 @ 09:23
    Kristina
    0

    Aaah yes, in fact all level1 have children, but some are hidden in navigation.

    So I tried like this:

    var subUrl (page.Children.Count()>&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?

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 09:28
    Fuji Kusaka
    0

    Try this instead

    var subUrl =(page.Children.Where("Visible").Count()>0)? page.Children.First().Url:page.Url;
  • Kristina 33 posts 49 karma points
    Apr 19, 2013 @ 09:32
    Kristina
    0

    It works! 

    Thanks a lot! 

    Kristina

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 09:56
    Fuji Kusaka
    0

    Great !!! :)

Please Sign in or register to post replies

Write your reply to:

Draft