OK, this is a tough one :)
I have top-level pages and child pages for each of them. Top-level pages have widgets. I would like to display the parent widgets in the child pages. Users can only add widgets to the parents and then the children will display those widgets without allowing anyone to edit them.
This means I need a way to pull widgets from another page.
Here's my idea. I'm in the child ASPX page. I get the parent's alias path and try to get its widgets like so:
ArrayList widget = AppContext.GetMediaBoxWidgets(CMSContext.CurrentDocumentParent.NodeAliasPath);
string w1 = widget.ToString();
In the child page, I'll use the w1 variable to show the content in an asp.net Literal.
My only problem is that I can't seem to get the right content for the widgets (i.e. the GetMediaBoxWidgets method).
Here's where it got me so far:
public static ArrayList GetMediaBoxWidgets(string pageAliasPath)
{
if (pageAliasPath == "")
return null;
var tree = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);
PageInfo pi = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, pageAliasPath, CMSContext.PreferredCultureCode, null, CMSContext.CurrentSite.CombineWithDefaultCulture);
if (pi == null) return null;
// Get template instance
PageTemplateInstance pti = CMSPortalManager.GetTemplateInstanceForEditing(pi);
if (pti == null) return null;
var pt = pi.PageTemplateInfo;
var webparts = pti.WebParts; // this is the widget xml with
}
And here's the xml that I'm getting:
<page><webpartzone id="zoneMediaLeft" widgetzonetype="editor"><properties><property name="visible">True</property><property name="disableviewstate">False</property><property name="containerhideonsubpages">False</property><property name="hideonsubpages">False</property><property name="useupdatepanel">False</property><property name="timezonetype">inherit</property></properties><webpart controlid="NCDANext3Events" type="NCDANext3Events" guid="e3c2dc0c-a41b-464b-8968-912ecaf1b10d" iswidget="true"><property name="filteroutduplicates">False</property><property name="showeditdeletebuttons">False</property><property name="visible">True</property><property name="showfirstlast">True</property><property name="shownewbutton">False</property><property name="contentafter"><div class="SeeAllEvents"><a href="~/Media-Events/Events.aspx"> See all events ></a></div>
</div></property><property name="disablemacros">False</property><property name="controlid">NCDANext3Events</property><property name="pagesize">10</property><property name="checkpermissions">False</property><property name="selecttopn">3</property><property name="classnames">cms.event</property><property name="pagenumbersseparator">-</property><property name="hidecontrolforzerorows">False</property><property name="backnextlocation">split</property><property name="relatednodeisontheleftside">False</property><property name="zerorowstext">No data found</property><property name="useupdatepanel">False</property><property name="path">/%</property><property name="maxrelativelevel">-1</property><property name="selectonlypublished">True</property><property name="transformationname">CMS.Event.WidgetNext3Events</property><property name="instanceguid">e3c2dc0c-a41b-464b-8968-912ecaf1b10d</property><property name="contentbefore"><div class="WidgetNext3Events">
<div class="EventsHeader">Next 3 Events</div></property><property name="disableviewstate">False</property><property name="orderby">EventDate DESC</property><property name="webparttype">NCDANext3Events</property><property name="enablepaging">False</property><property name="iswidget">True</property></webpart></webpartzone><webpartzone id="0"><properties /></webpartzone><webpartzone id="zoneMediaCenter" widgetzonetype="editor"><properties><property name="visible">True</property><property name="disableviewstate">False</property><property name="containerhideonsubpages">False</property><property name="hideonsubpages">False</property><property name="useupdatepanel">False</property><property name="timezonetype">inherit</property></properties><webpart controlid="editabletext_1" type="editabletext_1" guid="24e40545-2d79-4a22-8c5f-c9cf682a9ea9" iswidget="true"><property name="htmlareatoolbarlocation">Out:FCKToolbar</property><property name="regiontype">HtmlEditor</property><property name="disablemacros">False</property><property name="selectonlypublished">False</property><property name="webparttype">editabletext_1</property><property name="resolvedynamiccontrols">True</property><property name="minlength">0</property><property name="iswidget">True</property><property name="maxlength">300</property><property name="instanceguid">24e40545-2d79-4a22-8c5f-c9cf682a9ea9</property><property name="visible">True</property><property name="checkpermissions">False</property><property name="useupdatepanel">False</property><property name="wordwrap">True</property><property name="controlid">editabletext_1</property><property name="disableviewstate">False</property></webpart></webpartzone><webpartzone id="zoneMediaRight" widgetzonetype="editor"><properties><property name="visible">True</property><property name="disableviewstate">False</property><property name="containerhideonsubpages">False</property><property name="hideonsubpages">False</property><property name="useupdatepanel">False</property><property name="timezonetype">inherit</property></properties><webpart controlid="NCDALatestMediaUpdate" type="NCDALatestMediaUpdate" guid="62d05f38-9930-46d0-a8e1-042173f79709" iswidget="true"><property name="filteroutduplicates">False</property><property name="showeditdeletebuttons">False</property><property name="visible">True</property><property name="showfirstlast">True</property><property name="instanceguid">62d05f38-9930-46d0-a8e1-042173f79709</property><property name="disablemacros">False</property><property name="controlid">NCDALatestMediaUpdate</property><property name="pagesize">10</property><property name="checkpermissions">False</property><property name="selecttopn">1</property><property name="classnames">cms.news</property><property name="pagenumbersseparator">-</property><property name="hidecontrolforzerorows">False</property><property name="backnextlocation">split</property><property name="relatednodeisontheleftside">False</property><property name="zerorowstext">No data found</property><property name="useupdatepanel">False</property><property name="path">/%</property><property name="maxrelativelevel">-1</property><property name="selectonlypublished">True</property><property name="transformationname">CMS.News.WidgetLatestMediaUpdate</property><property name="disableviewstate">False</property><property name="shownewbutton">False</property><property name="selecteditemtransformationname">CMS.News.NewsDetail</property><property name="orderby">NewsReleaseDate DESC</property><property name="webparttype">NCDALatestMediaUpdate</property><property name="enablepaging">False</property><property name="iswidget">True</property></webpart></webpartzone></page>
Any suggestions?