Add a PageBuilder page using the Ektron API

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.

9 comments

  1. Oo, that’s a lot better/easier way to automaticaly add a widget than using the JSON technique the WorkArea uses!

      1. I can’t say I have seen this before when doing this. I have recently updated the code sample above so maybe the new code won’t cause this.

  2. Hi Chris,

    I am using 3-tier architecture for my project.

    How can i get my published pages in application layer to the presentation layer??

    please help…
    Regards,

    Jinshina E K

    1. Hi Jinshina

      My name is Rob – not Chris – but thats ok 🙂

      At this point in time, using the latest version of Ektron (8.6), you cannot deploy PageBuilder pages using 3-tier. When you use 3-tier you do place a number of restrictions on what you can do. For instance, you cannot use any of these Ektron technologies with 3-tier :

      – eSync
      – PageBuilder
      – Server Controls (e.g. ListSummary)

      The reason for this is that the 3-tier installation is very minimal; the presentation tier does not contain a full Ektron install so some of the more complex features will not work here. The presentation tier can do just that – “present” – it has to communicate with the business logic tier using the Framework API (over WCF) in order to do things like retrieve content.

  3. Rob – this is all well & good, but how are you generating the pageID being passed to the Get() method?
    pageModel.Get(pageID, out pageData, false);

    Given my experience with Ektron, this doesn’t seem like it would work.

    Also, some others have noted that they are getting an error on the checkout, but there doesn’t seem to be an overload to set the API access level. Any suggestions?

  4. Hi Dan
    I have updated the original post above with a more complete code sample. Hopefully this will answer your question.

  5. Rob, sorry to raise this post from the dead, but I’m a bit confused on the Settings property you’re using to set your Content block’s ID parameter. A code snip I found on the Ektron site involved a much longer string, effectively specifying an XML string to set all params. How are you identifying that the ID number you’ve provided, in fact, the ID?

Leave a comment