Copied to clipboard

Flag this post as spam?

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


  • meng 2 posts 22 karma points
    Mar 18, 2014 @ 08:50
    meng
    0

    razor syntax for OrderBy

    display as the breadcrumbs  Home > Category > Sub category,

    I want get Sub category > Category > Home.

    change the code

    @foreach (var page in CurrentPage.Ancestors().OrderBy("Level")) 

    or

    @foreach (var page in CurrentPage.Ancestors().OrderBy("Level desc")) 

    It didnt achieve.rendered HTML not any change!

    How can i do? thanks!

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 18, 2014 @ 10:16
    Fuji Kusaka
    0

    Hi Meng,

    If you want to display like this Home  > Category > Sub Category 

    @using umbraco.MacroEngines;
    @using umbraco.BusinessLogic
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    
        @{
    
               DynamicNode n  = new DynamicNode();
                List<DynamicNode> page = @Model.Ancestors().Where("Visible").Where("level > 1").Items;
    
    
                <ul>
                    @foreach(var item in page){
                        if(r.NodeTypeAlias =="homepageDocType"){
                                <li><a href="/">Home</a></li>
                        }
                        else{
                            var altUrl = (r.ChildrenAsList.Where(x=>x.GetProperty("umbracoNaviHide").Value != "1")?  r.ChildrenAsList.First().Url : r.Url;
                    <li class="current"><a href="@altUrl">@r.Name</a></li>
                        }
    
                    }
                    <li class="current">@CurrentModel.Name</li>
        </ul>
    
        }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 18, 2014 @ 17:33
    Dennis Aaen
    1

    Hi Meng,

    I assume that you're using Partial View Macros, if so I think this snippet do what you´re after. If you are using Razor Macro DynamicNode let me know and I will try to help you. But based on the code that you have posted, it seems to me that you are using MVC

    @inheritsUmbraco.Web.Macros.PartialViewMacroPage

    @if(CurrentPage.Ancestors().Any())
    {
       
    <ul class="breadcrumb">
           
    <li class="active">@CurrentPage.Name</li>

            @foreach (var page in CurrentPage.Ancestors().OrderBy("Level desc"))
            {
                <li>
    <span class="divider">></span> <a href="@page.Url">@page.Name</a></li>
           
    }
           
       
    </ul>
    }

    The code snippet above should give you a breadcrumb that looks like this: Sub category > Category > Home.

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Mar 19, 2014 @ 21:46
    Jeavon Leopold
    0

    Hi Meng,

    Dennis's snippet is correct and can be used directly in a view or partial view or a macro partial view.

    Did you try it?

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft