Getting a property from the nearest ancestor of document type
Im trying to do som recursivenes. I need to pull a value from a property from the nearest ancestor of two document types. Which ever is nearest...
@if (CurrentPage.HasValue("Kontaktpersoner")){
<p>CurrentPage has kontaktperson</p>
} else if (CurrentPage.AncestorsOrSelf("Sektion").First().HasValue("Kontaktpersoner")){
<p>Ancestor of doctype Sektion has kontaktperson</p>
} else if (CurrentPage.AncestorsOrSelf("Afdeling").First().HasValue("Kontaktpersoner"){ <p>Acncestor of doctype Afdeling has kontaktperson</p>
} else {
<p>No node has kontaktperson</p>
}
But this throws an error if both document types dont exist in the Ancestoror self scope.
@{ if (CurrentPage.HasValue("Kontaktpersoner", true)){ <p>CurrentPage has kontaktperson</p> } }
Then it will look recursively for the property value in ancestors. So if current page doesn´t have the property value then it will go up in the tree, until it found it.
Getting a property from the nearest ancestor of document type
Im trying to do som recursivenes. I need to pull a value from a property from the nearest ancestor of two document types. Which ever is nearest...
But this throws an error if both document types dont exist in the Ancestoror self scope.
How do i fix this?
Hi Claus,
If you do something like this:
Then it will look recursively for the property value in ancestors. So if current page doesn´t have the property value then it will go up in the tree, until it found it.
Hope this helps,
/Dennis
Holy c...
That was clean! and it works like a charm. I just cut my view in less than half.
Thanks a lot :)
is working on a reply...