Retrieving the document name of a specific child node with DocumentHelper in Macro

Lambert Chan asked on May 28, 2019 20:47

Hi I'm new to Kentico and web development and I'm currently having some difficulties using macro in the editable field for the web parts to dynamically fetch the name of a specific node in the tree. The path currently looks like main/test/pages and I'm trying to retrieve the name of the first folder.

The macro code that I'm using right now is {%DocumentHelper.GetDocuments().Path("/test/", PathTypeEnum.Children).DocumentName#%} which isn't giving me anything.

Thanks for any guidance!

Correct Answer

Brenden Kehren answered on May 28, 2019 21:05

Check out the Macro Console under the System app. System > Macros > Console. That will allow you to test macros with virtual and actual data.

Secondly, where are you trying to access this page from? Would it be a child of the current page? If it's the child, you can simply use something like:

{% CurrentDocument.Parent.DocumentName |(identity)GlobalAdministrator%}

Also, DocumentHelper.GetDocuments() is a C# method and not available using the K# macro engine.

3 votesVote for this answer Unmark Correct answer

Recent Answers


Lambert Chan answered on May 28, 2019 22:28 (last edited on December 10, 2019 02:31)

Thank you for that suggestion to use the Macro Console as I wasn't aware that option existed!

I'm trying to access the page from a separate node which is why current document didn't suffice. I tested your suggestion of: {% Documents["/test"].AllChildren.FirstItem.DocumentName |(identity)GlobalAdministrator%}

and it worked like a charm thank you.

1 votesVote for this answer Mark as a Correct answer

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