Configure the Constructor Function Parameter

When sites creates a new instance of the constructor function, it passes a parameter that contains contentItemData, scsData, and contentClient to help with content layout development.

Here is example code for the constructor function:

function ContentLayout(params) {
    this.contentItemData = params.contentItemData || {};
    this.scsData = params.scsData;
    this.contentClient = params.contentClient;
}
ContentLayout.prototype = {
    render: function (parentObj) {
        var content = {
            blogTitle: this.contentItemData.data['starter-blog-post_title'],
        };

        if (this.scsData) {
            content = $.extend(content, {
                'scsData': this.scsData
            });
        }

    }
};
return ContentLayout;

The constructor function parameter includes the following objects:

  • params.contentItemData: Contains the content item, including its name, description, ID, and data. For example, the field 'blogpost_title' in the content item can be accessed using params.contentItemData.data['blogpost_title'].

  • params.scsData::This object passes in information when the constructor is called from within sites. This object doesn’t exist for content layouts rendered in third-party applications. This object contains a Sites SDK object, the method contentTriggerFunction to raise a trigger, and the Details page links.

  • params.contentClient:This is the contentClient object created from the Content SDK and used to call the content layout. It is therefore configured with the appropriate parameters for the content server. If you need to make additional calls to the content server, you can use this contentClient object rather than creating your own. This object contains client APIs for the content. APIs are available to query, search, and get content items and their content types. Other helper APIs are also available; for example, expandMacros() to expand the macros used in rich text.