How to display child documents if they exist and display siblings if they don’t.

Kentico Support asked on November 30, 2012 12:26

How to display child documents if they exist and display siblings if they don’t.

Correct Answer

Kentico Support answered on November 30, 2012 12:26

You can insert the following macro to the Path property of your source web part (e.g. Repeater web part).  This macro can be used when you want to display either the child documents of the current document if they exist, or else, display the sibling documents of the current document when no child documents exist for the current document.

{%
if (CurrentDocument.Children.Count > 0) {
return "./%";
}
else {
return "../%";
}
#% }

When copying this macro example, please remove the space between the closing percent and bracket characters.


-jh-
0 votesVote for this answer Unmark Correct answer

Recent Answers


Matt Davis answered on July 31, 2014 19:29

How does this handle public permissions, is CurrentDocument.Children accessible when not logged in?

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on August 1, 2014 09:19

Hello Matt,

It depends on the version of Kentico you are running, in version 7 and 8 there is a web.config key you can add to get this working for public users too:

<add key="CMSCheckPermissionsForDocumentCollection" value="false"/>

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.