Set Content Path in Repeater Dynamically based on Node Level

Robert Srigley asked on September 5, 2019 16:36

I am trying to set the Content Path of a repeater based upon the node level of a page that inherits ( is nested ) the web part.

This code always returns false and does not execute.

{% level1 = "/{0}/{1}/%"; level2 = "/{0}/{1}/{2}/%"; if (CurrentPageInfo.NodeLevel != 2 || CurrentPageInfo.NodeLevel != 3 ){CurrentDocument.NodeAliasPath = level2} else { CurrentDocument.NodeAliasPath = level1 } %}

Not sure if I need to use a different class to set the path on the repeater, or my syntax is not correct.

Any help or ideas would be appreciated.

Thank you.

Correct Answer

Brenden Kehren answered on September 5, 2019 17:00

Your macro should read something like this:

{% level1 = "/{0}/{1}/%"; level2 = "/{0}/{1}/{2}/%"; if (CurrentDocument.NodeLevel != 2 || CurrentDocument.NodeLevel != 3 ){ level2 } else { level1 } |(identity)GlobalAdministrator%}

CurrentDocument and CurrentPageInfo are two different objects. When referencing documents on the live site, use CurrentDocument. This is most likely why you were always returning false. Also as Trevor mentioned, you don't want to set the current documents nodea alias path, you want to return the actual path to the property in the webpart.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on September 5, 2019 16:54

Not sure why you are setting CurrentDocument.NodeAliasPath, you should just be returning the /{0}/{1}/% or the other value for the Path property of the repeater.

I assume you are adjusting the Path property of the repeater, right?

1 votesVote for this answer Mark as a Correct answer

Robert Srigley answered on September 5, 2019 18:30

Thank you for the quick response Trevor and Brenden.

Trevor, yes, I was just trying to adjust the path of the repeater.

Brenden, you syntax, worked.

Thank you guys.

0 votesVote for this answer Mark as a Correct answer

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