This SharePoint 2013 tutorial, I am going to explain how to change layout of a Page in SharePoint 2013 or SharePoint 2016 or SharePoint Online. Page Layout basically defines the structure of the page.
We will also check how to add a custom web part to page layout in SharePoint 2013/2010 and then we will see how to fix issue Only Content controls are allowed directly in a content page that contains Content controls SharePoint 2013 Page Layout.
SharePoint Page Layouts
SharePoint 2013 default page layouts are One column, One column with sidebar, Two columns, Two columns with a header, Two columns with header and footer, Three columns, Three columns with a header, Three columns with header and footer, etc.
Change the page layout in SharePoint 2013
Now, I will show how can you change the page layout in SharePoint 2013/2016.
Edit the page (Settings -> Edit Page). Then from the FORMAT TEXT click on Text Layout and then select the page layout which you want to change.
Add custom web part to page layout in SharePoint 2013/2010
Now, we will see how to add web your custom web part to SharePoint 2013/2010 page layout.
There might be different ways to add a custom web part to the page layout in SharePoint 2013 or SharePoint 2010, but here we will discuss how we can add by modifying the onet.xml file.
Add a custom web part to the page layout in SharePoint
First of all after deploying your custom web part to the SharePoint website, Please visit this link to get the 4 part assembly name of the web part which is very much important.
Once you got the 4 part assembly name, Now go to the appropriate XML folder to modify the onet.xml file which in inside the SiteTemplates directory.
Here I am going to add my custom web part to a publishing web site. So my onet.xml is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\SiteTemplates\BLANKINTERNET\XML (Please change according to your site template).
In the next step take a back up of the onet.xml file, before modifying anything.
Now open the onet.xml file in Visual studio (Visible clear even you can open in notepad also) and search for <Modules> tag. Then check for <Module> tag. Remember we have to add web part inside <Module> tag.
Check for the module name, which means usually the module name has the link with page layout name (correct me if I am wrong). So if your page is using Homepage layout means you have to add in the module whose name is “Home”.
If you want to add more than one web parts then you have to add one by one in the onet.xml file inside the module tag.
So inside the <file> tag add the below webpart add code below the <property> tag.
<AllUsersWebPart WebPartZoneID="MyRightZone" WebPartOrder="1">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<assembly>TestVisualWebPartForLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a565f7cce9e306f5</assembly>
<type name="TestVisualWebPartForLayout.VisualWebPart1.VisualWebPart1, TestVisualWebPartForLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a565f7cce9e306f5" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="AllowZoneChange" type="bool">True</property>
<property name="ExportMode" type="exportmode">All</property>
<property name="HelpUrl" type="string" />
<property name="Hidden" type="bool">False</property>
<property name="TitleUrl" type="string" />
<property name="AllowConnect" type="bool">True</property>
<property name="Description" type="string">My WebPart</property>
<property name="AllowHide" type="bool">True</property>
<property name="AllowMinimize" type="bool">True</property>
<property name="Title" type="string">MyHelloWorld</property>
<property name="ChromeType" type="chrometype">Default</property>
<property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
<property name="Width" type="string" />
<property name="Height" type="string" />
<property name="HelpMode" type="helpmode">Modeless</property>
<property name="CatalogIconImageUrl" type="string" />
<property name="AllowEdit" type="bool">True</property>
<property name="TitleIconImageUrl" type="string" />
<property name="Direction" type="direction">NotSet</property>
<property name="AllowClose" type="bool">True</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</AllUsersWebPart>
As described above carefully give the assembly name and type name. Also, you can set the web part properties inside the <properties> tag. Also, other mail properties are WebPartZoneID, you have to give the zoneid which is present in the layout.
Once you will modify this save the onet.xml file and do an IISRESET which is mandatory to take into effect.
Only Content controls are allowed directly in a content page that contains Content controls SharePoint 2013 Page Layout
This SharePoint 2013 tutorial explains, how to resolve the issue Only Content controls are allowed directly in a content page that contains Content controls.
Recently I got an error while applying a page layout in a page in a SharePoint 2013 site. The error coming was
Sorry, something went wrong
An error occurred during the processing of /SiteURL/_catalogs/Pages/default.aspx. Only Content controls are allowed directly in a content page that contains Content controls.
The error came for a particular page layout. If I change to that page layout then the error comes.
Only Content controls are allowed directly in a content page that contains Content controls
Actually, there was an issue with the page layout.
I checked out the page layout in the SharePoint site and find out that:
<asp:content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
Here the problem was with “c” in the <asp:content. After I change to capital “C” it started working.
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
This is how to resolve the issue Only Content controls are allowed directly in a content page that contains Content controls.
You may like following SharePoint page layouts tutorials:
- How to include jQuery in SharePoint
- SharePoint Online redirect to another page programmatically
- How to Change SharePoint Site Logo + PowerShell
- How to Change favicon in SharePoint Online/2013/2016
- SharePoint Online redirect to another page programmatically
- http error 503. the service is unavailable in SharePoint 2013/2016/2010
- Download SharePoint Manager 2013/2010/2007/Online
- Web parts maintenance page: if you have permission, you can use this page to temporarily close web parts or remove personal settings. for more information, contact your site administrator
I hope this SharePoint 2013 tutorial helps to know how to change page layout in SharePoint 2013.
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.