Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
@CurrentPage.AncestorsOrSelf("Sektion").Last().Name
Gets me the name of the nearest page of the Doc Type "Sektion". But if no ancestor exists of this doc type, i get an error.
How do i check if an ancestor of the doc type "Sektion" actually exists?
Hi Cluas,
Maybe you could do something like this:
if(CurrentPage.AncestorsOrSelf("Sektion")!= null){ @CurrentPage.AncestorsOrSelf("Sektion").Last().Name}
Hope this helps,
/Dennis
Hi,
You need to check that the ancestor is not null before attempting to get any properties from it.
So try something like:
var sektion = @CurrentPage.AncestorsOrSelf("Sektion").Last();
var sektionName = (sektion != null) ? sektion.Name : string.Empty;
Cheers,
Maff
Using either of your suggestions i get:
Try using CurrentPage.AncestorsOrSelf("Sektion").Count() > 0 :-)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Getting name of nearest ancestor of specific document type
Gets me the name of the nearest page of the Doc Type "Sektion".
But if no ancestor exists of this doc type, i get an error.
How do i check if an ancestor of the doc type "Sektion" actually exists?
Hi Cluas,
Maybe you could do something like this:
Hope this helps,
/Dennis
Hi,
You need to check that the ancestor is not null before attempting to get any properties from it.
So try something like:
var sektion = @CurrentPage.AncestorsOrSelf("Sektion").Last();
var sektionName = (sektion != null) ? sektion.Name : string.Empty;
Cheers,
Maff
Using either of your suggestions i get:
Sequence contains no elements
Exception Details: System.InvalidOperationException: Sequence contains no elements
Try using CurrentPage.AncestorsOrSelf("Sektion").Count() > 0 :-)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.