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.
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.
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.
Then insert the rich text fields created into the layout by dragging the elements. Save and publish the page layout.
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 |