Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 09, 2012 @ 16:59
    Fuji Kusaka
    0

    OrdeBy Active Menu Content

    Is it possible to Order a list of content in a subNavigation depending on the active state ?

    Having a list of content and sub content within them 

    Content 1
    sub
    sub
    sub
    Content 2
    sub 
    sub
    Content 3
    sub sub sub

    So if am on sub content 2 i would like the display to Order like this 

    • Content 2
    • Content 1
    • Content 3
    //fuji

  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 10, 2012 @ 09:58
    Matt Bliss
    0

    You could just loop through the sub items twice.

    • On the first pass filter to only show where the page is the current page
    • On the second pass filter to show only those nodes that are not the current node
    Something like:
    for(pass=0; pass < 2; pass++)
    { foreach(var item in...
    {
    if (pass == 0 ? item.Id == Model.Id : item.Id != Model.Id)
    {
    //display item here
    }
    }
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 10, 2012 @ 10:21
    Fuji Kusaka
    0

    Hi Matthew,

    Not sure if this will do the trick though.....let me get back to you. 

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 10, 2012 @ 10:36
    Fuji Kusaka
    0

    Here is my source code btw

    @foreach(var res in rootNode.OrderBy("@test,  desc")){
    if(res.IsAncestorOrSelf(Model)){
    <div class="hotel-list-active">
    <div class="hotel-list-logo @Library.Join("-", @Model.AncestorOrSelf(3).Name,"mnu-logo").Replace(" ", "-")"></div>
       <div class="hotel-list-name-active"><span class="htl-active">@Model.AncestorOrSelf(3).Name</span></div>
    </div>
    if(res.Children.Count() > 0){
    <div class="hotel-page-nav">
    <ul>
    @foreach(dynamic content in res.Children.Where("Visible")){
    <[email protected]((content.IsAncestorOrSelf(Model)), " class=active", "")><a hrf="@content.Url" class="@Library.If((content.IsLast()),"spOff villas-color","")">@content.Name</a></li>
    }
    </ul>
    </div>
    }
    }
    else{
    <a href="@res.Children.First().Url">
    <span class="hotel-list">
    <div class="hotel-list-logo @Library.Join("-", res.Name,"mnu-logo").Replace(" ", "-")"></div><div class="hotel-list-name"><span class="htl">@res.Name</span></div>
    </span>
               </a>
    }

    the active part needs to display first with all its sub menus. Alternatively  i could order by Id, what could do the trick is i oder the parent depending on the Child.Id. That could make the trick what do you think ?

  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 10, 2012 @ 10:58
    Matt Bliss
    0

    Can't see why it wouldn't work. Here is my suggested logic applied to your <ul> (putting your check in for the current node). I've not syntax checked it so might need a little tweaking)

    <ul>
    @for(pass=0; pass < 2; pass++) { foreach(dynamic content in res.Children.Where("Visible")){ if(pass == 0 ? content.IsAncestorOrSelf(Model) : !content.IsAncestorOrSelf(Model)) { <[email protected]((content.IsAncestorOrSelf(Model)), " class=active", "")><a href="@content.Url" class="@Library.If((content.IsLast()),"spOff villas-color","")">@content.Name</a></li>
    }}}
    </ul>
    
  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 10, 2012 @ 11:04
    Matt Bliss
    0
  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 10, 2012 @ 11:50
    Fuji Kusaka
    0

    Am getting an error while saving :The name 'pass' does not exist....

     

  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 10, 2012 @ 12:17
    Matt Bliss
    0

    My mistake, try:

    @for(int pass=0; ...

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 10, 2012 @ 14:39
    Fuji Kusaka
    0

    Got it working Matthew,

    However i the main content folder needed  to move up first instead of the sub contents.  But got it working.

    @for(int pass=0; pass <1; pass ++){
    foreach(var res in rootNode){
    if(pass==0? res.IsAncestorOrSelf(Model):!res.IsAncestorOrSelf(Model)){
    <div class="hotel-list-active">
    <div class="hotel-list-logo @Library.Join("-", @Model.AncestorOrSelf(3).Name,"mnu-logo").Replace(" ", "-")"></div>
    <div class="hotel-list-name-active"><span class="htl-active">@Model.AncestorOrSelf(3).Name</span></div>
    </div>
    if(res.Children.Count() > 0){
    <div class="hotel-page-nav">
    <ul>
    @foreach(dynamic content in res.Children.Where("Visible")){
    <[email protected]((content.IsAncestorOrSelf(Model)), " class=active", "")><a href="@content.Url" class="@Library.If((content.IsLast()),"spOff villas-color","")">@content.Name</a></li>
    }
    </ul>
    </div>
    }
    }
    }
    }

    The only thing i needed to add the another for loop to display the other remaining descedants. Many thanks for your help though.

    //fuji

     

Please Sign in or register to post replies

Write your reply to:

Draft