Pagebuilder pages are an Ektron feature that allow content authors to create flexible web pages by dragging and dropping widgets onto the page. A widget is a module that can be added to a web page which provides a specific purpose such as an image, video, form or a block of HTML text.
There might be instances in which, during the course of a project, it becomes necessary to add pages into the CMS en masse, for instance, during a content migration excercise.
The following block of code below will allow you to create a Pagebuilder page and add a widget into it.
EDIT: Updated as original code sample wasn’t verbose enough
The code adds an Ektron ContentBlock control to the page.
long folderId = 86; // where to add the page to
var tmpPageData = new PageData(); // temporary object for page config
string controlUrl = "ContentBlock.ascx"; // name of the widget user control in widgets folder
string dropZoneId = "Middle"; // id of the DropZone control on the wireframe
var widget = new WidgetData
{
ControlURL = controlUrl,
ColumnID = 0,
Order = 0,
Minimized = false,
DropID = dropZoneId,
Settings = String.Format("{0}", 30);
};
tmpPageData.Widgets = new List(); // initialise widgetdata list on page
tmpPageData.Widgets.Add(widget); // add ContentBlock widget to page
// Create a drop zone data object
var dropZoneMain = new DropZoneData {DropZoneID = "Middle", Columns = new List()};
// Create a column data object
var columnDataMain = new ColumnData {columnID = 0, width = 100, unit = Units.percent};
// Add the column to the drop zone
dropZoneMain.Columns.Add(columnDataMain);
// Add the drop zone to the page
tmpPageData.Zones = new List {dropZoneMain};
tmpPageData.IsMasterLayout = false;
// Call a method to add the page (see method below)
AddPage(gameToPush.Title, gameToPush.Alias, folderId, 2, tmpPageData, 2057);
So the process above is add widgets to the PageData.Widgets property then add the Drop Zones to the PageData.Zones property (which also includes Columns).
The above code depends upon a method called “AddPage()” which is given below:
private void AddPage(string pageTitle, string alias, long folderId, long wireFrameId,
Ektron.Cms.PageBuilder.PageData pageData, int langId = 2057,
ContentMetaData[] metaData = null)
{
var pageManager = new PageModel();
var contentManagerOld = new Ektron.Cms.API.Content.Content();
pageManager.RequestInformation = contentManagerOld.RequestInformationRef;
var tmpPageData = new PageData();
// First create the page entity in the CMS
pageManager.Create(pageTitle, folderId, alias, langId, wireFrameId, String.Empty, "summary", out tmpPageData, true);
// Assign widgets and drop zones
tmpPageData.Widgets = pageData.Widgets;
tmpPageData.Zones = pageData.Zones;
// Save to the CMS
pageManager.CheckIn(tmpPageData);
pageManager.Publish(tmpPageData);
// Assign metadata
if (tmpPageData.pageID > 0)
{
if (metaData != null)
{
if (metaData.Length > 0)
{
contentManagerOld.ContentLanguage = langId;
foreach (ContentMetaData meta in metaData)
{
contentManagerOld.UpdateContentMetaData(tmpPageData.pageID, meta.Id, meta.Text);
}
}
}
}
}
At first glance this seems a bit counter-intuitive. The addition of widgets and drop zones to the page is done separately, whereas you may have thought that widgets go into columns which go into zones which go pages. In fact the widgets and zones are accessed through different properties as you can see above.
You must be logged in to post a comment.