Tuesday, 14 August 2018

Creating Page Layouts with Rich HTML Field Editors on Office 365 SharePoint

You would have seen several articles for creating page layouts with custom content types. But in this article let us look how to provision page layouts with multiple rich text fields.

Problem Statement: OOB publishing HTML field (Rich Field Text Column) can be used to create the content type for page layouts manually. But if you require more than one Rich Field Text Column, then we need to create those publishing HTML field programmatically.

Create Page Layout with Rich HTML Fields:

The following are the points to be considered while creating page layouts.
  • Create Site Columns
  • Create Site Content type
  • Add Site Columns to the Content type
  • Create Page Layout using the Content type.
Since few properties needs to enabled on a field, this is only possible with programming way. The field XML is built and then the field is created using the field XML.

This approach might be possible in multiple programming ways including PowerShell, CSOM PowerShell, CSOM, JSOM or REST API. But in the samples below, let us use PnP PowerShell for provisioning required components.

Create Site Columns: The rich field column needs to be created here. Let us create the column programmatically using field XML.

Note: Here you can add/remove the required constraints. The constraints are applied with the help of field control properties. The control properties are listed on the documentation site. For example, in the following sample embedding iFrames are allowed by setting the AllowEmbedding property to true. Similarly, other control properties like AllowExternalUrls, AllowFonts, AllowHtmlSourceEditing, etc., can be set.

The following snippet shows adding the field/column using XML.

Create Content Type and Add Fields to Content Type: The custom content type is created by setting base content type. The base content type is Page. Once the custom content type is created, the custom created fields can be added. The following snippet shows both operations.

Create Page Layout Manually: Go to SharePoint Designer and create a page layout from the option available on the designer ribbon. Provide the custom page layout name and associate the custom content type by selecting the same.
Create Page Layout by associating Content Type
Create Page Layout by associating Content Type

Then insert the rich text fields created into the layout by dragging the elements. Save and publish the page layout.
Inserting Rich Text Fields into Page Layout
Inserting Rich Text Fields into Page Layout

Create the page using custom page layout created. The below snapshot shows the edited page with the rich text columns created.
Page using Rich Text Fields Layouts
Page using Rich Text Fields Layouts