ASPX templates
Version 6.x > ASPX templates > Getting widgets from another page View modes: 
User avatar
Member
Member
ovidiu-e-cubed - 11/9/2011 11:32:21 AM
   
Getting widgets from another page
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?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 11/13/2011 7:47:03 PM
   
RE:Getting widgets from another page
Hello,


we are solving the issue via e-mails but for other visitors:

Impossible is to get the rendered HTML code from the XML structure of web parts. But - it is possible to display the widgets from another page by the mentioned approach:

You get the XML structure from the parent's PageInfo and then assign it to the child's PageInfo. The only condition is that the source and target pages must have a zone with the same name.


Best regards,
Helena Grulichova

User avatar
Member
Member
francis.harvey-irisco - 1/10/2013 8:58:33 AM
   
RE:Getting widgets from another page
Hi Helena,

How can we extract the content of a page to show it dynamically on another place, like in a literal control...

My issue is pretty the same thing,

We've created a web part that use javascript to display animated content,
I wanted to use a Path property to specified a folder in the tree containing Portal page to extract content and display it in a litteral control or something else...

Is this impossible? with 5.5R2...

Francis Harvey

User avatar
Member
Member
mohamed.chorfa-irisco - 1/17/2013 8:38:58 AM
   
RE:Getting widgets from another page
Hello
How can we extract the content of a page to show it dynamically on another place, like in a literal control...

My issue is pretty the same thing,

We've created a web part that use javascript to display animated content,
I wanted to use a Path property to specified a folder in the tree containing Portal page to extract content and display it in a litteral control or something else...

Is this impossible? with 5.5R2...

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 2/4/2013 9:43:33 AM
   
RE:Getting widgets from another page
Hello,

There are more ways to do that.
Depending on which type of content do you want to dynamically display in another place, you could use simply the identical elements of a page template and point the DataSource (Path) to the the same source (e.g. when displaying News or similar), or you could use the WebClient, make a request and get the rendered content you need (which is rather less effective), or use an iframe...

When you're using javascript-animated content web part, maybe it's only about the proper transformation.
Could you please optionally provide more details about your aim?
Thank you in advance for information.

Regards,
Zdenek