Steps To Create Custom Page Layouts In SharePoint 2013 Using Visual Studio

Page layouts are the page templates, which define how a page should look, what page fields and content fields are present and which elements should be present on the page. The users can then create new publishing pages, which are based on the page layout format. In this article, I will explain how to create custom page layout in SharePoint 2013, using Visual Studio.

Pre-Requisites

  1. Open Visual Studio.
  2. Open New Project dialog box. Expand Office/SharePoint node and then choose SharePoint Solutions.



  3. Choose SharePoint 2013 – Empty Project template. Name the project as CustomSharePointProject.



  4. Choose the Deploy as a farm solution Radio option button and choose Finish button.



  5. “CustomSharePointProject” SharePoint project got created.


Create Page Layouts

  1. Right click on CustomSharePointProject -> Add -> New Folder.



  2. Name the folder as “PageLayouts”.



  3. Right click on “PageLayouts” folder ->Add -> New Item.



  4. Add module from the Add New Item Window. Name it as “CustomPageLayout”.



  5. PageLayout creates in the folder structure, given below-



  6. Rename the Sample.txt file as CustomLayout.aspx.

    CustomLayout

  7. Replace the content of the page layout with the text, given below. We can add site columns, content types, Webpart place holder in the page layout.


    1. <%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>  
    2.     <%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    3.         <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    4.             <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    5.                 <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    6.                     <asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">  
    7.                         <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server" /> </asp:Content>  
    8.                     <asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">  
    9.                         <ui>  
    10.                             <li><span style="color:red">This is new Custom Page Layout </span></li>  
    11.                             <li><span style="color:Blue">Page layouts are page templates that define how a page should look, what page fields and content fields are available, and which elements should be present on the page. Users can then create new publishing pages that are based on these page layouts, and their new pages for each specific type of content will follow a consistent format. </span></li>  
    12.                             <li><span style="color:Black">The End</span></li>  
    13.                         </ui>  
    14.                     </asp:Content>  
  8. Put the code, given below in Elements.xml file. Modify according to your folder structure. I have created it as icle page content type.


    1. <Module Name="CustomPageLayout" List="116" Url="_catalogs/masterpage" RootWebOnly="TRUE">  
    2.     <File Path="CustomPageLayout\CustomLayout.aspx" Url="CustomLayout.aspx" Type="GhostableInLibrary" ReplaceContent="TRUE" Level="Published">  
    3.         <!-- Page Layout Options -->Property Name="ContentTypeId" Value="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D" />  
    4.         <Property Name="UIVersion" Value="15" />  
    5.         <Property Name="ContentType" Value="Page Layout" />  
    6.         <Property Name="_ModerationStatus" Value="0" />  
    7.         <Property Name="FSObjType" Value="0" />  
    8.         <Property Name="PublishingAssociatedContentType" Value=";#Article Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#" />  
    9.         <!-- Specific Options -->  
    10.         <Property Name="Title" Value="Custom Page Layout" />  
    11.         <Property Name="PageDescription" Value="Example Custom Page Layouts" /> </File>  
    12. </Module>  
  9. List="116" Url="_catalogs/masterpage" RootWebOnly="TRUE" attributes need to be add in <Module> tag.
  10. Type="GhostableInLibrary" ReplaceContent="TRUE" Level="Published" attributes needs to be added in <File> tag.
  11. Build and deploy SharePoint solution.
  12. Open SharePoint site and open the Page library.



  13. Click “New Document” from Files tab -> Article Page.



  14. Give Page Title, Description and URL value. Select our newly created page layout from the dropdown page layouts.

    Put following code in Elements.xml file. Modify according to your folder structure. I have created it as icle Page Content type.

  15. Our new page creates with the “Custom Page Layout”.



  16. Open the newly created page. It will apply our custom page layout.


Summary - Thus, you have learned how to create a custom page layout in SharePoint 2013, using Visual Studio.