How to dynamically change properties of some web part or widget

   —   
This article describes how to dynamically change properties of web parts or widgets inserted on a document in the content tree.
A prerequisite of this API example in case of widgets is that the widget is inserted in the CMS Desk –> Content –> Edit - > Design tab and the Widget zone type is Customization by page editor. The example shows how to select appropriate template and modify property of requested web part/widget.

// Select page info of particular document
PageInfo pi = PageInfoProvider.GetPageInfo("CorporateSite", "/", "en-us", "", false,ConnectionHelper.ContextConnection);

//Get information about the template which is used by document
PageTemplateInfo pt = pi.PageTemplateInfo;

//Select zone which is a part of above template
WebPartZoneInstance wpzi = pt.GetZone("zoneLogo");

//Select web part or widget from the above zone
WebPartInstance wpi = wpzi.GetWebPart("ScrollingNews");

//Here you can get or set properties of widget or web part
wpi.SetValue("ContentBefore", "myValue");

PageTemplateInfoProvider.SetPageTemplateInfo(pt);

-it-


See also: Getting page template data

Applies to: Kentico CMS 5.5 R2
Share this article on   LinkedIn