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
    Jul 22, 2013 @ 10:15
    Fuji Kusaka
    0

    Next Siblings where Visible

    Hi guys,

    I need to create a Next & Previous button but somehow forgot about  visible or not!! 

    Can someone point out how do i get next or previous button to jump to the next or previous visible node if any is present to work.

    Tried something like this but 

    if(m.Next() != null && m.Next().GetProperty("umbracoNaviHide").Value !="1"){
            @m.Next().Name
        }

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 10:24
    Fuji Kusaka
    0

    Even tried that 

     while(m != null){
          if(m.Visible){
                break;
            }
            m = m.Next();
        }

        

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 22, 2013 @ 11:00
    Warren Buckley
    0

    Hey Fuji
    What is m? DynamicNode, strongly typed IPublishedContent?

    This is how I would possibly do it, get all the nodes in a collection that are visible then do a loop over that, like so.

    var nodes = Current.Children.Where(x => x.Visible());
    foreach(var node in nodes)
    {
       if(node.Next() != null)
       {
           <h2>@node.Name</h2>
       }
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 11:10
    Fuji Kusaka
    0

    Hey Warren,

    Nope not exactly what i was trying to achieve here. Well i have the following struc

    - Content
    -- Home
    --- Goods
    ---- Article 1 (Visible) 
    ---- Article 2 (Not Visible) 
    ---- Article 3 (Not Visible) 
    ---- Article 4  (Visible) 

    So let says am on Article 1 i should be able to get a Next Button which will redirect me to Article 4. 

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 22, 2013 @ 11:24
    Warren Buckley
    0

    Hmm wonder what happens if you just do
    @Current.Next().Visible() 

    or this
    @Current.Parent.Children.Where(x => x.Visible) (Not ideal as going upto the parent)

    Warren

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 11:30
    Fuji Kusaka
    0

    Did something like this 

     var m = @CurrentModel;
    if(m.Next() != null){
            if(m.Next().GetProperty("umbracoNaviHide").Value !="1"){
              <a href="@m.Next().Url">Next</a>
            }
            else{
      <a href="@m.Next().Visible">Next</a> </div>
    }
        }

    But here its not jumping to the next visible node.

    Btw Current.Next().Visible() aint working for me am on 4.11

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2013 @ 11:33
    Fuji Kusaka
    0

    From the previous post it is actually working but am not able to get the right URL .

    <a href="@m.Next().Visible.Url ?? ">Next</a>

     


  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 22, 2013 @ 11:38
    Warren Buckley
    0

    Hey Fuji,
    This is because it is just getting the next node regardless of the value of umbracoNaviHide.
    Hence you probably need to try and do this:

    @Current.Parent.Children.Where(x => x.Visible) 
  • Mike Chambers 636 posts 1253 karma points c-trib
    Jul 22, 2013 @ 11:38
    Mike Chambers
    0

    what about an alternative approach.. get all your descendants from the homepage Nodelike a site map.. then skipt to yout currenr and find prev/next

     

    var homePageNode = @Model.AncestorOrSelf(1);
        DynamicNode homePage = new DynamicNode(homePageNode.Id);
    
        DynamicNode[] nodelist = homePage.DescendantsOrSelf().Items
            .Where(x => x.HasAccess
                && x.GetPropertyValue("cascadeToChild") != "1"
                && x.GetPropertyValue("disableInNavigation") != "1" && ANY OTHER FILTERS).ToArray();
    

     

            DynamicNode prev = nodelist.Reverse().SkipWhile(x => x.Id != @Model.Id).Skip(1).FirstOrDefault();
            if (prev != null)
            {
                <li class="page-prev"><a href="@prev.Url" title="@prev.GetPropertyValue("altTitle")"><i class="icon-chevron-left"><span>prev</span></i></a></li>    
            }
            else
            {
                <li class="page-prev disabled"><a href="#" title=""><i class="icon-chevron-left"><span>prev</span></i></a></li>
            }
    
            DynamicNode next = nodelist.SkipWhile(x => x.Id != @Model.Id).Skip(1).FirstOrDefault();
            if (next != null)
            {
                <li class="page-next"><a href="@next.Url" title="@next.GetPropertyValue("altTitle")"><i class="icon-chevron-right"><span>next</span></i></a></li>
            }
            else
            {
                <li class="page-next disabled"><a href="#" title=""><i class="icon-chevron-right"><span>next</span></i></a></li>
            }
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 22, 2013 @ 17:20
    Jeavon Leopold
    0

    Seems mad now, but I once did this for this same problem:

        var filteredNext = new DynamicNode(Model.Id).GetFollowingSiblingNodes().Where(x => x.GetProperty("umbracoNaviHide").Value != "1");
        if (filteredNext.Any())
        {
            <p>next not hidden: @filteredNext.First().Url</p>
        }

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 23, 2013 @ 14:10
    Fuji Kusaka
    0

    Hi Jeavon,

    What did you use to get "GetFollowingSiblingNodes " ? Are you using uComponents here ?

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 23, 2013 @ 14:36
    Jeavon Leopold
    0

    Hi Fuji,

    It's in umbraco.NodeExtensions so you just need to add @using umbraco; to the top of your Razor file.

    Thanks,

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 23, 2013 @ 14:47
    Fuji Kusaka
    0

    Is this not in v6 ? Cos am actually on a v 4.11 version.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 23, 2013 @ 15:12
    Jeavon Leopold
    0

    Nope, v4.8+ :-)

    Full example:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    @using umbraco;
    @{
        var filteredNext = new DynamicNode(Model.Id).GetFollowingSiblingNodes().Where(x => x.GetProperty("umbracoNaviHide").Value != "1");
        if (filteredNext.Any())
        {
            <p>next not hidden: @filteredNext.First().Url</p>
        }
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 23, 2013 @ 16:40
    Fuji Kusaka
    0

    My Mistake!! 

    @using umbraco.MacroEngines;
    @using umbraco;

    instead of

    @using  umbraco.MacroEngines
    @using umbraco; 

    Thanks Jeavon

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 23, 2013 @ 18:01
    Jeavon Leopold
    0

    Cool, you can of course do a simular thing for the previous link with the GetPrecedingSiblingNodes method

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jul 23, 2013 @ 18:45
    Mike Chambers
    0

    Forgive me if I'm worng.. but say...

    • axes.viz
    • what I want from Next node from "Opaque 14x9" would be Plastic.. this wouldn't be retreived by GetFollowingSiblingNodes as plastic is a parent not sibiling??


      So I'd have to start doing a lot of branching... depenadnat on if the sibling/descendant/parent/ancestor had the properties I wanted (like visible) hence why I suggested a get the sitemap for you filter and then skip to/take the next node?


      Not sure which approach might be more efficient.. but I think we'd need more than next/prev sibling for this to work?

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 23, 2013 @ 18:54
    Jeavon Leopold
    0

    Hi Mike, absolutely, if you wanted to navigate through different levels of the tree using Previous and Next then you would need a filterable sitemap!

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jul 23, 2013 @ 18:57
  • Charles Afford 1163 posts 1709 karma points
    Jul 23, 2013 @ 21:11
    Charles Afford
    0

    Yea i would be using DynamicNode and then just use the methods on that :)

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 25, 2013 @ 21:38
    Jeavon Leopold
    0

    The code I suggested does the same as the standard .Next() method but allows you to filter beforehand

Please Sign in or register to post replies

Write your reply to:

Draft