Copied to clipboard

Flag this post as spam?

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


  • Joseph Harrison 4 posts 24 karma points
    Feb 18, 2012 @ 11:26
    Joseph Harrison
    0

    Show home page in navigation

    Hi,

    I cant seem to get my homepage to show up in my navigation menu.

    Here is my code...........

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ 
        var homePage = @Model.AncestorOrSelf(1);
        if (homePage != null)
        {
        <ul id="navigation">
            @foreach (var item in homePage.Children.Where("Visible"))
            {
                if (Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value) > 0)
                {
                    var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
                    <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li>
                }
            }
        </ul>
        }
    }

     

    Any help is appreciated

    Thanks

  • Tony McBeth 8 posts 29 karma points
    Feb 18, 2012 @ 13:13
    Tony McBeth
    0

     

    Hi Joseph,

    Just add your home page in manually before looping through the children;

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
       
    var homePage =@Model.AncestorOrSelf(1);
       
    if(homePage !=null)
       
    {
       
    <ul id="navigation">

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

           
    @foreach(var item in homePage.Children.Where("Visible"))
           
    {
               
    if(Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value)>0)
               
    {
                   
    var selected =Array.IndexOf(Model.Path.Split(','), item.Id.ToString())>=0?" class=\"selected\"":"";
                   
    <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li>
               
    }
           
    }
       
    </ul>
       
    }
    }

    Hope this helps,

    Tony

  • Joseph Harrison 4 posts 24 karma points
    Feb 19, 2012 @ 01:13
    Joseph Harrison
    0

    Thanks for your help tony

    I modified it so that it also sets the class if selected

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;
    @{ 
        var homePage = @Model.AncestorOrSelf(1);
        if (homePage != null)
        {
        <ul id="navigation">
            @{
                var homepageSelected = Model.Id == homePage.Id ? " class=\"selected\"" : "";
                <li><a @Html.Raw(homepageSelected) href="@homePage.Url">@homePage.Name</a> </li>
            }
    
            @foreach (var item in homePage.Children.Where("Visible"))
            {
                if (Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value) > 0)
                {
                    var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
                <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li>
                }
            }
        </ul>
        }
    }
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies