Copied to clipboard

Flag this post as spam?

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


  • Natasha 79 posts 195 karma points
    Dec 17, 2013 @ 13:06
    Natasha
    0

    If statement for url picker on accordion menu

    Hi There 

    I really need some help with razor.  I am fine with XSLT but cannot figure out how to put in an if statement in my menu.  I have a url picker with the alias 'pageNameInMenu' I would like the user to be able to select content or an external url for any given page.  I have been able to fdo this for my XSLT menu's but can't figure it out in razor.  I'm using Umbraco Version 6.1.5 and this is my menu script.  Any help would be appreciated even pointing me to a tutorial would be very helpful.

    Thanks

    Natasha

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{ 
    @*Get the root of the website *@
        var root = Model.AncestorOrSelf(1);
    }



    <ul id="accordion">
        @foreach (var page in root.Children.Where("Visible"))
        { 
            <li class="@page.IsAncestorOrSelf(Model, "current", "noncurrent")">
                <a href="@page.Url">@page.Name</a>
    <ul>
    @foreach (var grandchildpage in page.Children.Where("Visible"))
       

    <li>
                <a href="@grandchildpage.Url">@grandchildpage.Name</a>
    </li>

    }
    </ul>

            </li>
    }
    </ul>
  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 17, 2013 @ 13:35
    Fuji Kusaka
    0

    Hi Natasha,

    Am not sure where you are using the urlPicker here but as a guess i would try somethin like

    @{ 
    if(page.HasValue("pageNameInMenu")){
    @page.pageNameInMenu
    }
    else {
    @page.Url
    }
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Dec 17, 2013 @ 13:41
    Dennis Aaen
    0

    Hi Natasha,

    Since you want to be able to select content or an external url for any given page, I think that you should have a look on uComponents and their URL Picker.

    In the documentation for the URL Picker there is a Razor example. I hope this can help you to what you want.

    /Dennis

  • Natasha 79 posts 195 karma points
    Dec 17, 2013 @ 14:32
    Natasha
    0

    Thank you both for your help, but where exactly do I put this code.  I have tried it under the for each statement, but that throws an error.  What it shoulde be is if the url has a conent or external link the select that else use the Li I hope that makes sense?

    Thanks again.  

     

  • Natasha 79 posts 195 karma points
    Dec 17, 2013 @ 16:02
    Natasha
    0

    Fuji your code works beautifully for the 1st level nav but it returning nothing for the 2nd level anyone give me any pointers on what I'm doing wrong?  Code below:

     

    @inherits umbraco.MacroEngines.DynamicNodeContext
     
     
    @{ 
    @*Get the root of the website *@
        var root = Model.AncestorOrSelf(1);
    }
     
     
     
     
    <ul id="accordion">
     
        @foreach (var page in root.Children.Where("Visible"))
        { 
     
            <li class="@page.IsAncestorOrSelf(Model, "current", "noncurrent")">
    @{ 
    if(page.HasValue("pageLinkInMenu")){
    <a href="@page.pageLinkInMenu.Url">@page.Name</a>
    }
    else {
     <a href="@page.Url">@page.Name</a>
    }
    }

               

     
    <ul>
    @foreach (var grandchildpage in page.Children.Where("Visible"))
        { 
     
    <li>
    @{ 
    if(Model.Content.HasValue("pageLinkInMenu")){
    <a href="@page.pageLinkInMenu.Url">@page.Name</a>
    }
    else {
    <a href="@grandchildpage.Url">@grandchildpage.Name</a>
    }
    }

                

    </li>
     
    }
    </ul>
     
            </li>
    }
    </ul>
  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 17, 2013 @ 16:30
    Fuji Kusaka
    0

    You mean in the grandchildpage ?

    If so you need to check in the grandchildpage as well not in Model.


  • Natasha 79 posts 195 karma points
    Dec 19, 2013 @ 12:51
    Natasha
    0

    Got it working

    Thanks so much you're a super star

Please Sign in or register to post replies

Write your reply to:

Draft