If Current Document is First Child of Parent, Show Parent Title

Bryan Johnson asked on August 5, 2015 15:36

I'm trying to figure out how to determine if a page is the first child of its parent and I can't seem to get it.

I have the parent page set up to redirect to the first child. The using portal page inheritance, I'm using the parent page as a template to set the look and feel for all of its children. I'd like to be able to display the name of the current page using a macro that was placed on the parent page; however, if the current page is the first child of the parent, I'd like that macro to show the title of the parent page.

My page structure looks something like this:

> Academic Programs (redirects to first child)
>> Overview <<show parent title>>
>> Undergraduate Programs <<show own title >>
>> Graduate Programs <<show own title >>

I couldn't find a way to determine of the current page is the first child, so I changed the parent's "Inactive menu item redirect to URL" to the overview page path and used this macro code to write out the page title: {% (CurrentDocument.NodeAliasPath == CurrentDocument.Parent.DocumentMenuRedirectUrl) ? CurrentDocument.Parent.GetValue("DocumentName") : CurrentDocument.GetValue("DocumentName") #%}

Looking at the values in "CurrentDocument.NodeAliasPath" and "CurrentDocument.Parent.DocumentMenuRedirectUrl" I think this should work properly, but must be missing something.

I'm sure this is a complete newbie question, but can someone help me out?

Thanks,

Sean

Correct Answer

Brenden Kehren answered on August 5, 2015 15:41

Check the NodeOrder and if needed the NodeLevel. The order should be 1 to be the first item in the child level.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Bryan Johnson answered on August 6, 2015 01:56

This worked like a charm, feel silly for missing it... thank you!

Side note: Any reason my approach - admittedly not the best way - didn't work?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 7, 2015 14:53

For starters CurrentDocument.NodeAliasPath == CurrentDocument.Parent.DocumentMenuRedirectUrl CurrentDocument is the page you are navigating to. You need to compare the pages being output to the page they are navigating to. I'm not sure it would be 100% accurate but something like Eval("NodeAliasPath") == CurrentDocument.Parent.DocumentMenuRedirectUrl.

0 votesVote for this answer Mark as a Correct answer

Bryan Johnson answered on August 7, 2015 18:29

Ah, that makes sense now. I really appreciate the help :-).

0 votesVote for this answer Mark as a Correct answer

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