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>
}
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>
}
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.
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>
}
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.
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!
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?
Also tried this:(Doesn't work either)
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?
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
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.
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
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
No joy Gary... No node list - It's not giving the error though.
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
Hi Steve, May be you could try doing something like
Fuji,
What were you using for the var "list"?
Gary,
I am using webforms
I've even tried this. Gives me an error.
With the NodeById being the "Course Descriptions" node.
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?
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
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!
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
is working on a reply...