Create A Custom Page Layout For SharePoint Online

In the previous article, we have discussed creating a custom master page in SharePoint Online using HTML, CSS, Design Manager. In this article, we will create a page layout. Page layouts can be thought of a customized layout of contents in SharePoint. The contents may include placeholders for Web part zones, image gallery, etc.

The concept is the same as before and revolves around these high-level steps,

  • Create a new page layout using Design Manager
  • Make the modifications in the Page Layout as per requirement
  • Get a code for inserting web part zones
  • Edit any page to use the new page layout

Our goal is to create a page layout that will look like this,

Create a custom Page Layout for SharePoint Online

 

Follow along with the steps to get it completed!

Step 1 - Create a new page layout using Design Manager

Navigate to your design manager from the settings icon in your site. Once it opens, click on “Edit Page Layouts” available on the right-hand side quick launch.

Create a custom Page Layout for SharePoint Online

Click on “Create a Page Layout”

Create a custom Page Layout for SharePoint Online

 

Fill in the details in the next screen. The following information is needed.

Create a custom Page Layout for SharePoint Online

 

Name - The name of the Page layout that we are creating (SPSPageLayout in our case)

Master Page - The parent master page where the Page layout will be associated. (spsindustries)

Content Type - The content type under whose listing our newly created template will appear(Articles in our case)

Clicking on OK will redirect you to the page creation confirmation page as shown below,

Create a custom Page Layout for SharePoint Online

 

Notice that the page layout is still in draft state. We will complete it very soon. Follow along with the next steps.

Step 2 - Make the modifications in the Page Layout as per requirement

If you click on the “Conversion Successful” link of the previous screen (shown above) you will be redirected to the Preview page of the page layout. By default, it contains some existing elements as placeholders (Page Image, Page Content, etc.)

Create a custom Page Layout for SharePoint Online

Now, to make our modifications we will have to make use of SharePoint Designer (SPD). Open the site in SPD, and navigate to “Page Layouts” section in the right-hand quick launch bar,

Create a custom Page Layout for SharePoint Online

The concept is the same as editing Master pages – edit only the HTML part and the ASPX page will be refreshed with updates. Next, check out the HTML page (SPSPageLayout.html) and click on “Edit File in Advanced Mode”. This will open the file in SPD.

Create a custom Page Layout for SharePoint Online

Create a custom Page Layout for SharePoint Online

 

It can be noticed that the existing elements/placeholders that come along with the page layout by default are placed in “divs” inside the HTML as seen below. Idea is to get rid of these elements and then include our own HTML. For inserting SharePoint components in our page layouts, we will make use of “Snippets”. We will build our page layout something of this sort,

Create a custom Page Layout for SharePoint Online

 

Now, after removing the default SharePoint Components we go ahead and write down our own custom HTML inside the page layout. Make sure that all your HTML is written inside the asp content placeholder with ID “PlaceHolderMain”. The screenshot below depicts the same (removing existing SharePoint components and where to write our custom HTML)

Create a custom Page Layout for SharePoint Online

Insert a small HTML table snippet as shown below in the space reserved in previous screen. Think of the HTML table as the container for inserting our web part zones. Here is the HTML below,

Create a custom Page Layout for SharePoint Online

  1. <p style="color:red"><b>SPS Industries Communities Services</b> - We actively look for Volunteers interested in lending a helping hand</p>  
  2. <table style="width:90%; min-height:300px">  
  3.     <tr>  
  4.         <td rowspan="2" style="border:2px solid red"> Space for Webpart Zone 1 </td>  
  5.         <td style="border:2px solid green"> Space for Webpart Zone 3 </td>  
  6.     </tr>  
  7.     <tr>  
  8.         <td style="border:2px solid green"> Space for Webpart Zone 3 </td>  
  9.     </tr>  
  10. </table>  

Step 3 - Get code for inserting web part zones

Click on the Preview page as shown in Step 2, and click on “Snippets” link present in the right hand top corner.

Once the Snippet page opens, click on “Web Part Zone” as shown in the image below. On clicking the link, the HMTL snippet will be generated with a unique ID (every time you click on the “Web Part Zone” a new unique ID is generated and integrated with the HTML snippet).

On a side note, there are a whole bunch of snippets available in the Snippets gallery. Do explore the other types. The usage is the same for every type of them. Select the snippet type and a new code of HTML snippet will be generated which can then be copy-pasted and used in your SPD

Create a custom Page Layout for SharePoint Online

Copy the HTML snippet and paste the entire code in the HTML table’s first cell (i.e. inside the first <td> block replacing the “Space for Web part Zone 1”.

Repeat this step 2 more times. Make sure that you click on Web Part Zone and the page refreshes with a new ID, before copy-pasting the HTML snippet.

The code will look similar to this,

Create a custom Page Layout for SharePoint Online

 

On completion of the code save the page, check-in and then Publish a major version.

Create a custom Page Layout for SharePoint Online

Step 4 - Edit any page to use the new page layout

Now - all the heavy-lifting has been done, and it is time to reap the benefits of your hard work.

Go ahead and click on the “Edit” page. It can be noticed that the SPSPageLayout can be found under Articles content type. Select that and see the page change its layout to the one you’ve created!

Create a custom Page Layout for SharePoint Online

Create a custom Page Layout for SharePoint Online

There you go! The screen above shows how a page looks on using the newly created customized page layout.

This article can also be found in my personal blog – SharePoint Surgeon.