CurrentDocument.Parent is not returning any value

Brijesh Singh asked on January 30, 2018 22:45

Our macro is failing on child page while accessing the information of parent page.

Below both are working on parent page.

{%CurrentDocument.GetValue("TOC")#%} {%CurrentDocument.TOC#%}

On child page , below is failing.

{%CurrentDocument.Parent.GetValue("TOC") #%}

It is working fine in Kentico 8.2 but stopped working after migration to 9.0. Any help would be highly appreciated.

Correct Answer

Ilesh Mistry answered on January 31, 2018 08:18

You could try and see if CurrentDocumentParent.GetValue(“TOC”) works for you DocumentContext Kentico 9

1 votesVote for this answer Unmark Correct answer

Recent Answers

Dragoljub Ilic answered on January 31, 2018 12:09 (last edited on December 10, 2019 02:31)

Hi Brijesh,

Looks like the problem is that you are trying to retrive custom field on parent page type. If that is the case, you must combine you query (macro method) with 'WithAllData' method. Try something like this: {% Documents.WithAllData.Where("NodeAliasPath='" + CurrentDocument.Parent.NodeAliasPath + "'")[0].GetValue("TOC") |(identity)GlobalAdministrator%}

This should solve your issue. You can modify where condition how ever suits you best, but 'WithAllData' is necessary.

Best regards, Dragoljub

2 votesVote for this answer Mark as a Correct answer

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