Get child field value

Mark Ellis asked on October 13, 2014 06:35

Hi, I'm trying to find out how to get the value of a child's custom field.

We have some documents that have Grandchild with a field "Copy". The structure is as below:

Document ---> Child --------> GrandChild

We're using a web part with the following that works well.

I'd like to replace it with something like the below code but that's not quite working.

<meta property="og:description" content="{% FacebookShareDescription|(default)CurrentDocument.Children[0].Children[0].GetValue("Copy") #%}" />

I've tried adding some code into the PortalTemplate.aspx.cs as well but even when debugging and passing in various aliasPaths I still can't get the field value.

TreeProvider treeProvider = new TreeProvider(); NodeSelectionParameters childrenSelectParams = new NodeSelectionParameters(); childrenSelectParams.AliasPath = string.Format("{0}/%", aliasPath); childrenSelectParams.MaxRelativeLevel = 1; TreeNodeDataSet children = treeProvider.SelectNodes(childrenSelectParams);

var hopefullyNotNull = children.Items[0].GetValue("Copy");

Is there some code I can use for either approach? The first would be preferred.

Correct Answer

Jan Hermann answered on October 13, 2014 15:58

Hello,

I have tested it and following macro should work:

{%FacebookShareDescription.ToString()==""?Documents.WithAllData[CurrentDocument.Children.FirstItem.Children.FirstItem.GetValue("NodeAliasPath")].GetValue("copy"):FacebookShareDescription|(identity)GlobalAdministrator%}

Best regards,
Jan Hermann

0 votesVote for this answer Unmark Correct answer

Recent Answers


Mark Ellis answered on October 13, 2014 07:07 (last edited on March 24, 2018 12:15)

Sorry this is the existing part

<meta property="og:description" content="{%FacebookShareDescription|(default)Default text here%}" />

0 votesVote for this answer Mark as a Correct answer

Mark Ellis answered on October 14, 2014 06:18

Perfect. Thanks.

0 votesVote for this answer Mark as a Correct answer

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