3

I'm Creating Page Layout using SharePoint designer. Using the below code i created Web part zone

<WebPartPages:WebPartZone  runat="server" Title="ZoneTit" ID="ZoneId">
    <ZoneTemplate></ZoneTemplate>
    </WebPartPages:WebPartZone>

I want to add the web part(dwp file) to the page layout using SPD2013? If i create the page using the custom layout, it automatically bring all the web parts to the corresponding zone(Don't want to add the web parts to the page manually). How can i achieve this?

1 Answer 1

3

If you can deploy your page layout with a sharepoint solution it would be quite easy, you can add your webparts to the elements.xml file which includes your page layout:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="PageLayouts" List="116" Url="_catalogs/masterpage">
    <File Path="PageLayouts\UAGSearchPage.aspx" Url="Umdasch/UAGSearchPage.aspx" Type="GhostableInLibrary" ReplaceContent="true">
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
      <Property Name="Title" Value="UAG-Searchpage" />
      <AllUsersWebPart WebPartZoneID="RefinementWebPart" WebPartOrder="1">
      <!-- Refinement Panel -->
      <![CDATA[<webParts>
            <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                <metaData>
                     <type name="Microsoft.Office.Server.Search.WebControls.RefinementScriptWebPart, Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
                     <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                </metaData>
               <data>
               <properties>
               ...
               ...
</Elements>

Pagelayout.aspx:

<asp:Content ID="LeftNavBar" ContentPlaceHolderID="PlaceHolderLeftNavBar" runat="server">
    <div class="wpxp-webpartzone" id="wpxp-searchRefinement">
        <WebPartPages:WebPartZone runat="server" AllowPersonalization="false" ID="RefinementWebPart" FrameType="None"
                    Title="<% $Resources:wpxpUmdasch, WPZoneRefinement;%>" Orientation="Vertical"><ZoneTemplate></ZoneTemplate>
        </WebPartPages:WebPartZone>
    </div>
</asp:Content>

When i open the file in sharepoint designer after the deployment it looks like as follows:

<asp:Content ID="LeftNavBar" ContentPlaceHolderID="PlaceHolderLeftNavBar" runat="server">
    <div class="wpxp-webpartzone" id="wpxp-searchRefinement">
        <WebPartPages:WebPartZone runat="server" AllowPersonalization="false" ID="RefinementWebPart" FrameType="None"
                    Title="<% $Resources:wpxpUmdasch, WPZoneRefinement;%>" Orientation="Vertical"><ZoneTemplate>
        <spsswc:RefinementScriptWebPart runat="server" SelectedRefinementControlsJson="..." UseManagedNavigationRefiners="False" QueryGroupName="Default" RenderTemplateId="~sitecollection/_catalogs/masterpage/Display Templates/Filters/Control_Refinement.js" StatesJson="{}" ServerIncludeScriptsJson="null" Title="Refinement" FrameType="None" SuppressWebPartChrome="False" Description="This webpart helps the users to refine search results" IsIncluded="True" ZoneID="RefinementWebPart" PartOrder="2" FrameState="Normal" AllowRemove="True" AllowZoneChange="True" AllowMinimize="True" AllowConnect="True" AllowEdit="True" AllowHide="True" IsVisible="True" DetailLink="" HelpLink="" HelpMode="Modeless" Dir="Default" PartImageSmall="" MissingAssembly="Cannot import this Web Part." PartImageLarge="" IsIncludedFilter="" ExportControlledProperties="True" ConnectionID="00000000-0000-0000-0000-000000000000" ID="g_2a9274f8_a121_4fe4_ad4f_4ecb4f53e80d" ChromeType="None" ExportMode="All" __MarkupType="vsattributemarkup" __WebPartId="{2A9274F8-A121-4FE4-AD4F-4ECB4F53E80D}" WebPart="true" Height="" Width=""></spsswc:RefinementScriptWebPart>

        </ZoneTemplate></WebPartPages:WebPartZone>
    </div>
</asp:Content>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.