Convert the Path value of a Web Part to a Document Object or Collection of Document Objects

Jay Heavner asked on March 7, 2016 23:33

I have a Repeater Web Part. It's Path value is set as ./SomeChild/%. In my HTML Envelope I would like to use the DocumentName of the parent of the repeated content; basically the DocumentName of SomeChild.

If I use the macro {% Path %} then it renders ./SomeChild/% but it appears to be text and not an Object. Is there another macro that I can pass that output to in order to get a Document Object or, given that there's a wildcard at the end, a collection of Document Objects that I could .First().Parent().DocumentName()?

Basically I want to display the parent Document Name of my repeated content as a header. There has to be an obvious way to do this but I can't figure it out.

Recent Answers


Trevor Fayas answered on March 8, 2016 15:41

The macro "Documents" or "RootDocument" may be where you need to go.

Here's some examples:

{% Documents["./SomeChild/%"].First().DocumentName() %} {% RootDocument.AllChildren.Where("NodeID=" + QueryString.ID)[0].GetValue("NodeAliasPath") #%} {% Documents.WithAllData["/MyNode/Path"].DocumentMenuRedirectUrl %}

For your particular example, if you can just remove the /% from it, you can do:

{% Documents[Path.Replace("/%","")].DocumentName() %}

if this helped, please mark as answered

0 votesVote for this answer Mark as a Correct answer

Jay Heavner answered on March 9, 2016 15:20

{% Documents["./SomeChild/%"]%} is not valid. What goes inside the brackets needs to be a fully qualified path and the Path property of the web part is not that.

The following expression works for this UC but is not a scalable solution. It would break if the path were {0}/{1}/% or ../% {% docPath = Path.Replace(".", CurrentDocument.NodeAliasPath).Replace("/%", ""); return Documents[docPath].DocumentName #%}

If there were a macro that resolved the web part Path property into a well-formed path then it would work. Imagine something like: {% Path.ResolvePath() %} that turned ./SomeChild/% into /root/FirstLevel/SecondLevel/CurrentDocument/SomeChild

0 votesVote for this answer Mark as a Correct answer

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