Copied to clipboard

Flag this post as spam?

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


  • Erick 19 posts 89 karma points
    Jan 06, 2016 @ 21:32
    Erick
    0

    get doc-type for page in multiple levels in content tree

    Hi,

    I need to make some changes a websites navigation and page structure and need some help

    In the back office, only Menu Items could be children of the home node and Pages could be children of the a Menu Item

    In order to get the current page doc type I did this

    var MenuItem = Model.Content.AncestorOrSelf(2);
    var Page = MenuItem.Children.Where(x => x.DocumentTypeAlias == DocumentTypeAliases.PAGE).First();
    

    I also created a side panel navigation to be displayed at the side of the page like so

    var PageChildren = Page.Children;
    
     if (PageChildren.Any())
                {
                    foreach (var Item in PageChildren)
                    {
                    <li>
                        <a href="@Item.Url" class="top-level">@Item.Name</a><span><i class="fa fa-caret-right accordion-toggle"></i></span>
                        @if (Item.Children.Where("Visible").Count() > 0)
                        {
                            <ul class="sub-menu">
                                @foreach (var SubItem in Item.Children.Where("Visible"))
                                {
                                    <li><a href="@SubItem.Url">@SubItem.Name</a></li>
                                }
                            </ul>
                        }
                    </li>
                    }
                }
    

    I now need to be able to also add Pages as children to the Home Node, but if I try to navigate to one of those pages it throws a null exception for obvious reasons.

    can any one offer suggestions for the best way to achieve this?

    If anyone knows of some good tutorials covering this type of stuff that would also be great

    thanks

Please Sign in or register to post replies

Write your reply to:

Draft