Optimal Macro Question for Accessing Parent Page Info

Jared Gotte asked on April 8, 2016 00:22

We will start using Content Staging soon and I just found out that all of our web part visibility macros using NodeIDs will only work on one server. This web part visibility macro in particular was very useful: {% CurrentPageInfo.NodeParentID == 1234 #}

We also want to avoid using something like {% CurrentDocument.Parent.DocumentName == "Parent Page" #%} since it's not utilizing the cached page info.

The best I have so far is {% CurrentPageInfo.DocumentNamePath.Contains("/Path/To/Parent Page/") #%} but it returns true on all child pages - which you might not always want. This macro also works pretty well for instances where you might have something ugly like this: {% CurrentPageInfo.DocumentName == "Parent Page" || CurrentDocument.Parent.DocumentName == "Parent Page" || CurrentDocument.Parent.Parent.DocumentName == "Parent Page" || CurrentDocument.Parent.Parent.Parent.DocumentName == "Parent Page" #%}

Anyway... my question is: is there a better approach for creating visibility macros which rely on the parent page's name/id? The main constraint here is that it needs to be optimal.

(Secondary question, just in case I am misinterpreting the way content staging works, is it granular enough to choose not to sync web part visibility macros?)

Thanks!

Recent Answers


Jay McCormack answered on April 8, 2016 00:49

For content staging, it's not granular enough to not sync the visibility macros.

In relation to your macro, I can't help thinking there's a better way to do what you're doing. Applying visibility based on the parent document name/id seems a bit restricting. Is there no category you could assign to the current page instead, or another indicator on the page (Page Type property for example)?

Failing that - you could probably do a comparison of both the DocumentNamePath and the CurrentDocument.DocumentNode.NodeLevel, which would allow you to at least stop it resolving to true for child documents. And that property should be cached (I think).

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on April 8, 2016 03:02

Jared, you could use NodeGuid - it should be the in both instances in case you push your changes using staging all the time.

But I think your approach with visibility macro is not the best. For example when you check parent with macro - I'd build just another template for the section/branch under that parent.

1 votesVote for this answer Mark as a Correct answer

Zach Perry answered on April 8, 2016 20:22 (last edited on December 10, 2019 02:30)

GUID is synced across environments as Roman mentioned, which would be an alternative to using ID if you really want to go down that path, but since you are using CurrentPageInfo for the cached information, I don't think that would be an option. You could always just cache the macro itself: {% Cache(CurrentDocument.Parent.DocumentName == "Parent Page")|(identity)GlobalAdministrator%}

Can read the documentation to learn more about it.

0 votesVote for this answer Mark as a Correct answer

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