looping through the forest... uSkinned Source v1 & traversing nodes issue
I'm using the uSkinned Source v1 starter kit and have nested resource sections below a general page clone called "Resources":
Resources (USNResourcePage)
Page Components
Main Resources (USNResourcesSectionAN)
resource.pdf (USNResource)[media]
ChildResourcePage(USNResourcePage)
Page Components
Child Resources1(USNResourcesSectionAN)
resource1A.pdf (USNResource)[media]
Child Resources2(USNResourcesSectionAN)
resource2A.pdf (USNResource)[media]
resource2B.pdf (USNResource)[media]
resource2C.pdf (USNResource)[media]
Child Resources3(USNResourcesSectionAN)
resource3A.pdf (USNResource)[media]
resource3B.pdf (USNResource)[media]
I'm trying to loop through each section and list it's children accordingly alongside it's title if needed but no matter what I try I can't hook into the correct node to cascade down? I know it's my loop that's the issue but need another set of eyes to show me where I'm wrong!
I can now loop through the parent, children, and grandchildren of the nodelist but I'm exiting the traverse helper too quickly so my nested lists aren't as deep as they should be?
Amended structure:
Resources (USNResourcePage)
Page Components
Main Resources (USNResourcesSectionAN)
resource.pdf (USNResource)[media]
ChildResourcePage(USNResourcePage)
Page Components
Child Resources1(USNResourcesSectionAN)
resource1A.pdf (USNResource)[media]
Child Resources2(USNResourcesSection
AN)
resource2A.pdf (USNResource)[media]
resource2B.pdf (USNResource)[media]
resource2C.pdf (USNResource)[media]
Child Resources3(USNResourcesSectionAN)
resource3A.pdf (USNResource)[media]
resource3B.pdf (USNResource)[media]
Which in turn renders Main Resources page resources as such:
<ol role="list" class="resource__downloads--listing">
<li><a role="button" href="/media/1075/the-source_.pdf" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1076/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1081/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1078/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1073/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1074/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1077/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1083/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1080/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1085/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1079/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1082/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1084/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
</ol>
And the ChildResourcePage resources as such:
<ol role="list" class="resource__downloads--listing">
<li><a role="button" href="/media/1072/the-source_.pdf" rel="nofollow,noreferrer"><span>the-source.pdf</span></a>
<ol class="resource__downloads--nested">
<li>
Section heading of the Child Resources2 section
<a role="button" href="/media/1088/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a>
<ol start="A">
<li><a role="button" href="/media/1086/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1087/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1091/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1092/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
<li><a role="button" href="/media/1097/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>the-source.pdf</span></a></li>
</ol>
</li>
</ol>
</li>
</ol>
However the ChildResourcePage should render as such:
<ol role="list" class="resource__downloads--listing">
<li><a role="button" href="/media/1072/the-source_.pdf" rel="nofollow,noreferrer"><span>the-source.pdf</span></a>
<ol class="resource__downloads--nested">
<li>
Section heading of the Child Resources2 section
<ol start="A">
<li><a role="button" href="/media/1088/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>A1 the-source.pdf</span></a></li>
</ol>
</li>
<li>
Section heading of the Child Resources3 section
<ol start="B">
<li><a role="button" href="/media/1086/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>B1 the-source.pdf</span></a></li>
<li><a role="button" href="/media/1087/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>B2 the-source.pdf</span></a></li>
<li><a role="button" href="/media/1091/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>B3 the-source.pdf</span></a></li>
<li><a role="button" href="/media/1092/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>B4 the-source.pdf</span></a></li>
<li><a role="button" href="/media/1097/the-source_.pdf" target="_blank" title="Link will open in a new window/tab" rel="nofollow,noreferrer"><span>B5 the-source.pdf</span></a></li>
</ol>
</li>
</ol>
</li>
</ol>
And finally the updated current partial view code that needs updating:
looping through the forest... uSkinned Source v1 & traversing nodes issue
I'm using the uSkinned Source v1 starter kit and have nested resource sections below a general page clone called "Resources":
I'm trying to loop through each section and list it's children accordingly alongside it's title if needed but no matter what I try I can't hook into the correct node to cascade down? I know it's my loop that's the issue but need another set of eyes to show me where I'm wrong!
Please help me Obi Wan Umbraco, you're my only hope!
Hi Jon,
Which page (doctype) is your Razor script running on?
I'm guessing that it's the
USNResourcesSection_AN
pages?But do you want this to work higher up the tree? (e.g. on the
USNResourcePage
pages too)Cheers,
- Lee
Hi Jon,
Try looping descendents rather than children:
@foreach (var item in Model.Descendents.Where(x => x.IsDocumentType("USNResource")).OrderBy(x => x.SortOrder))
Thanks all,
Been head down, taken your thoughts on board:
@lee - yes that's where the script is due to the partial views of the starter kit
@Marc - I've changed the direction of attack as I realised I was trying to walk the nodes recursively instead of traversing as I should have.
I'm almost there I think, just to make sure the node adjustments I've made are right for the end result!
Feel free to add any other comments!
Jon
Sorry, I didn't mean where was the filepath of the script, but where is it being rendered from on the website, (e.g. which node/URL?)
I couldn't figure out the context of the
Model
.@Lee, the
Model
changes due to the nested partials. Having said that the code is almost there but I'm jumping out of the helper too early now:any thoughts?
J
@Lee, I realised what you were asking and the
Model
is the USNResourcePage partial "Resources" and "Child Resources" in the amended site structure:Does this help?
Hi Jon,
I still think your issue is that you are looking for children, not descendants from the Resource Page.
USNResource is a descendant of the USNResourcePage so using children will not find anything.
Try changing your code so that you are looking for descendants.
@marc, @lee, et al:
I can now loop through the parent, children, and grandchildren of the nodelist but I'm exiting the traverse helper too quickly so my nested lists aren't as deep as they should be?
Amended structure:
Which in turn renders Main Resources page resources as such:
And the ChildResourcePage resources as such:
However the ChildResourcePage should render as such:
And finally the updated current partial view code that needs updating:
Thanks everyone!
Hi Jon,
To be honest, I'm getting a bit cross-eyed with the script, (although I'm not sure if that's the colour/styling of the code-block on the forum?).
You could try swapping the
.Parent
reference in this line:... to ...
... but I'm not entirely sure if that solves the overall problem?
Cheers,
- Lee
Just to say thanks to @Marc and @Lee for their help as it gave me the chance to loop through and keep debugging until the issue was resolved! <3
For future readers, I ended up changing the main loop and the final element structure as well as removing the traverse loop to step through the lists.
If anyone has any further thoughts please feel free to comment!
h5yr!
is working on a reply...