In our custom page layouts, we can add web parts to the templates in two ways. First, we can add them to a web part zone template. This adds the web part to the web part zone when a page is created with the page layout and they can be modified or removed after the page has been created.
Secondly, we can reference the web part directly on the page outside of web part zones. This will insert the web part onto the page, but it cannot be modified or removed from the page when editing the page in the SharePoint web interface.
In this recipe, we will add two web parts to our page layout (one inside a web part zone template and one outside a web part zone). We will use the page layout we created previously with the three web part zone columns as a starting point.
Follow these steps to create a page layout with web parts added to the page:
PageLayout_ThreeColumn.aspx
(for our example, we have renamed it PageLayout_WebPartsAdded.aspx
).PageLayout_WebPartsAdded.aspx
page layout.PageLayout_WebPartsAdded.aspx
page layout.<div class="ms-table ms-fullWidth">
element.<div>
elements, add a TableOfContentsWebPart
element.<PublishingWebControls:TableOfContentsWebPart ID="TableOfContentsWebPart" Title="Table of Contents" runat="server" />
<div>
column containers as shown in the following code:<div class="ms-table ms-fullWidth"> <div class="ms-table ms-fullWidth"> <div class="cell-margin tableCol-33"> </div> <div class="cell-margin tableCol-33"> </div> <div class="cell-margin tableCol-33"> </div> </div> <SharePointWebControls:ScriptBlock runat="server"> if(typeof(MSOLayout_MakeInvisibleIfEmpty) == "function") {MSOLayout_MakeInvisibleIfEmpty();}</SharePointWebControls:ScriptBlock> </div>
ZoneTemplate
of one of the WebPartZone
elements, add a MediaWebPart
as shown in the following code:<WebPartPages:WebPartZone runat="server" Title="<%$Resources:cms,WebPartZoneTitle_Center%>" ID="CenterColumn"> <ZoneTemplate> <PublishingWebControls:MediaWebPart ID="MediaWebPart" Title="Media Web Part" runat="server" /> </ZoneTemplate> </WebPartPages:WebPartZone>
Web Parts Added
).Web parts are ultimately ASP.NET server controls at their core. As such, they can be added directly to a page layout like any other server control. Doing so puts them on the page, but does not let users edit them in the web interface.
Web part zones are server controls that provide a section of the page that users can add web parts to in the web interface. They also have a template that allows a page layout to include web parts in the zone by default when the content page is created. These web parts can be edited in the web interface after the content page is created.
3.144.30.236