Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Feb 11, 2013 @ 20:00
    Steve
    0

    Finding Following Sibling's Children

    I have a bit if navigation that needs to find the children of the sibling directly after it in the node tree. I tried using .Next() and the script fails to load. What am I missing?

    @{
        var root = Model.AncestorOrSelf();
        var courses = root.Descendants(5).Where("Name.Contains(\"Course Descriptions\")");
        var list = courses.Children;
        <div id="left-nav">
            <ul>
            @foreach(var item in list){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • Steve 472 posts 1216 karma points
    Feb 11, 2013 @ 20:16
    Steve
    0

    Also tried this:(Doesn't work either)

    @{
        var root = Model.AncestorOrSelf();
        var courses = root.Descendants("Course Descriptions");
    
        <div id="left-nav">
            <ul>
            @foreach(var item in courses.Children){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • Steve 472 posts 1216 karma points
    Feb 11, 2013 @ 20:32
    Steve
    0

    This SHOULD work, but it doesn't! If I remove the "Children" from the foreach it returns the corret parent "Course Descriptions", but I need a list of the children of Course Descriptions. Any suggestions? 

    @{
        var root = Model.AncestorOrSelf();
        var courses = root.Descendants().Where("Name == \"Course Descriptions\"");
    
        <div id="left-nav">
            <ul>
            @foreach(var item in courses.Children){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • gary 385 posts 916 karma points
    Feb 11, 2013 @ 22:30
    gary
    0

    Hi Steve

    If the navigation is on the node and just needs to list child pages for that node;

    @foreach (var item in CurrentPage.Children) should be sufficient.

    If you need to put the navi somewhere else, or on the child page(s);

    var root = CurrentPage.AncestorOrSelf("CourseDescriptions").Children()

    @foreach (var item in root).

    This has worked for me, but I remember my hints helped before so hopefully they can again - if I have the wrong end of the stick, let me know, will be around the rest of the evening.

    G

  • Steve 472 posts 1216 karma points
    Feb 11, 2013 @ 22:45
    Steve
    0

    I have tried this with no luck. Any other suggestions Gary? If this helps - "Course Descriptions" is the node name of the parent, of the children, I need in my navigation. The children as well will need to have this same navigation.

     

    @{
        var root = Model.AncestorOrSelf("Course Descriptions").Children;
    
        <div id="left-nav">
            <ul>
            @foreach(var item in root){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • gary 385 posts 916 karma points
    Feb 11, 2013 @ 22:50
    gary
    0

    Hi Steve

    Will have a more extensive look, but on first glance, try brackets after Children, ie .Children()

    I use NiceUrl and one of the new things is that it became NiceUrl(), don't know if Url() will help.

    Will paste exactly what I am using in a minute to see if we can find a way.

    G

  • gary 385 posts 916 karma points
    Feb 11, 2013 @ 22:56
    gary
    0

    Hello

    Just recreated it your way, using Model

        var root= Model.Content.AncestorOrSelf("Course Descriptions").Children;

    with my alias has returned exactly as I had, so should work for you by adding the Content.

    How did it go?

    G

     

  • Steve 472 posts 1216 karma points
    Feb 11, 2013 @ 23:02
    Steve
    0

    No joy Gary... No node list - It's not giving the error though. 

  • gary 385 posts 916 karma points
    Feb 11, 2013 @ 23:08
    gary
    0

    Odd, just looked through the code and it does use Url(), not NIceUrl()

    Other than that, just confirm, I remember its V6, are you using Mvc or webforms?

    G

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 12, 2013 @ 03:59
    Fuji Kusaka
    0

    Hi Steve, May be you could try doing something like

    @foreach(dynamic item in list.AncestorOrSelf(2).Descendants("Course Descriptions")){
    }
  • Steve 472 posts 1216 karma points
    Feb 12, 2013 @ 14:38
    Steve
    0

    Fuji,

    What were you using for the var "list"?

  • Steve 472 posts 1216 karma points
    Feb 12, 2013 @ 14:39
    Steve
    0

    Gary,

    I am using webforms

  • Steve 472 posts 1216 karma points
    Feb 12, 2013 @ 15:49
    Steve
    0

    I've even tried this. Gives me an error.

     With the NodeById being the "Course Descriptions" node.

    @{
        var root = Model.NodeById(21595);
    
    
        <div id="left-nav">
            <ul>
            @foreach(var item in root.Children){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • Steve 472 posts 1216 karma points
    Feb 12, 2013 @ 15:55
    Steve
    100

    Got it! I have NO idea, why I would have to call the node id to get it to work. Shouldn't I have been able to use this:

    var root = Model.AncestorOrSelf("Course Descriptions")

    Instead of this?

    @{
        var root = Model.AncestorOrSelf().NodeById(21595);
    
    
        <div id="left-nav">
            <ul>
            @foreach(var item in root.Children){
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
            </div>
    }
  • gary 385 posts 916 karma points
    Feb 12, 2013 @ 16:23
    gary
    0

    Hi Steve

    Just got back to machine - first. happy you got something - sorry I couldn't help more. 

    My feeling is that this is something like a typo, or something very obvious. It may be worth checking the gap that seems to exist between Course and Descriptions, maybe it is interpreted as Course-Descriptions, hence not being able to call it, or the capital is small case or vice versa, because all though we use the different forms, I think you seem to have tried every combination and I agree, it should work. (Not trying in any way to be smart, I have made these mistakes and spent literally hours trying to work out what I had got wrong)

    It may be useful to just call the documentTypeName (sorry Steve, maybe different in webforms, think it's nodeTypeAlias) ie call @item.nodeTypeAlias and this will give you the definitive spelling. Convinced it is somethng that simple.

    Good luck G

     

  • Steve 472 posts 1216 karma points
    Feb 12, 2013 @ 16:27
    Steve
    0

    Thanks Gary.

    I had to use the NodeById instead of the nodeTypeAlias because the parent and the children used the same doctype otherwise I would have. Thanks for all your help! I am fairly new to razor and never used C#, so It's all a learning processs. Love it though!

  • gary 385 posts 916 karma points
    Feb 12, 2013 @ 16:36
    gary
    0

    Ah - so there was the answer . Couldn't differentiate between the parent and child.

    Thinking that next time, you may call the parent doctype something different to distinquish it?

    The devil is in the detail, always.

    Enjoy helping out, helps my learning process by looking at issues other than my own.

    Até ja

    G

Please Sign in or register to post replies

Write your reply to:

Draft