Webpart to API Converter

by Trevor Fayas (HBS)
Webpart to API Converter preview

Price

$0

Details

Licence:
Free
Works with:
8.0, 8.1, 8.2, 9.0, 10.0, 11.0
Version:

Web site

http://www.avastonetech.com

Summary

This web part converter allows you to turn an existing web part into an API, Feed, or File output.

Description

This web part converter allows you to:

  • Turn a Smart Search results into an API for “suggested search” results.
  • Turn a  Repeater/Hierarchy Viewer into an API to retrieve objects in JSON
  • Turn a  Custom Table Repeater into a queryable API or XML feed.
  • Turn a  an Events Repeater into events subscription page or event file (ics)

Kentico has many great tools that allow users to display their web content in many different ways. However, they lacks a way to leverage this to create Web APIs. This web part converter bridges that gap, by allowing you to select a Web part on a page to act as an API.

Included is a Page Type (WebpartToAPI.SampleTransformations) that contains sample transformations for Repeaters, Hierarchy Viewers, Event Lists, and Smart Search Results, and documentation describing configuration.

Preview image

Comments


Trevor Fayas commented on

I re-submitted this for 8, 8.1, and 8.2 that includes the above fix.

Trevor commented on

A small note. I tried this on a Repeater that used a Data Source, and it tried to render the webpart before the data source kicked in.

To adjust, replace the SetupControl() method with the below. This renders the control's content at the last stage (the unload) and worked.

protected void SetupControl()
{
if (this.StopProcessing || IsDesign)
{
// Do not process
}
else
{


List<Control> allControls = new List<Control>();
GetControlList<Control>(Page.Controls, allControls);
Control specifiedWebpart = null;
foreach (var childControl in allControls )
{
if (childControl.ID == WebpartID) specifiedWebpart = childControl;
}
if (specifiedWebpart == null) throw new Exception("Webpart ID Not found");

// Convert to CMSAbstractWebPart and call the ReloadData to ensure it's ready to be rendered
theControl = (CMSAbstractWebPart)specifiedWebpart;
// special case for smart search results.
if (theControl.FindControl("srchResults") != null)
{
// Search results, handle differently
var srchItem = theControl.FindControl("srchResults");
// May or may not work.
ASP.cmsmodules_smartsearch_controls_searchresults_ascx srchResults = ((ASP.cmsmodules_smartsearch_controls_searchresults_ascx)srchItem);
srchResults.OnSearchCompleted += CMSWebParts_Custom_WebpartToApiConverter_OnSearchCompleted;
}
else
{
// Attach to the Unload as it's the final step of the webpart so all data binding and stuff is complete.
theControl.Unload += theControl_Unloaded;
}

}
}

void theControl_Unloaded(object sender, EventArgs e)
{
CMSAbstractWebPart theControl = (CMSAbstractWebPart)sender;
// Build the HTML String to render the control.
StringBuilder stringBuilder = new StringBuilder();
using (StringWriter textWriter = new StringWriter(stringBuilder))
{
using (HtmlTextWriter writer = new HtmlTextWriter(textWriter))
{
writer.Write(ContentBefore);
theControl.RenderControl(writer);
writer.Write(ContentAfter);
}
}
renderOutput(stringBuilder.ToString());
}