How can I reference another web part on the same page from a macro on a different web part?

Jake Burgy asked on January 28, 2015 18:40

For example, if I have "WebPart1" (doesn't matter what type of web part), and I wanted to link its visibility to another web part ("WebPart2") on the same page, what would I type for a macro expression?

I have tried {% CurrentDocument["WebPart2"].Visibility %} and {% CurrentDocument.DocumentContent["WebPart2"].Visibility %} but neither of these work.

How can I reference another web part's properties on the same page via a macro?

Recent Answers


Brenden Kehren answered on January 28, 2015 21:40 (last edited on December 10, 2019 02:30)

You could do something like this in the visibility property of the webpart. "headereditabletext" is the ID of the editable text webpart I am checking to see if there is any content in it. The requirement was to make it optional and it has design related styling around it so I hide it to remove the unnecessary styling if it is empty.

{% (ViewMode != "LiveSite") || (CMSContext.CurrentDocument.headereditabletext != "") |(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on January 28, 2015 23:15

Following code gets the property of the particular web part, so now you need to place it in appropriate event for 'consumer' web part and assign the value of the property you need.

CMSAbstractWebPart webpart1 = PagePlaceholder.FindWebPart("WebPart1"); string wp1Container = ValidationHelper.GetString(webpart1.GetValue("Container"), "");

To avoid web part customization, I'd recommend creation of the alternative layout for the 'consumer' web part, which will be the same as default +

<script runat="server"> your handler for onLoad, or any better event </script>

0 votesVote for this answer Mark as a Correct answer

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