2

I am working on a SharePoint server 2013 (latest build number ​15.0.4875.1000). and i am facing a problem when saving a site as template. As the custom master page will no be applied to any new site created based on the template

Now here is the scenario to reproduce the problem:-

  1. I created a new site collection of type Team site.
  2. I enable these 2 features inside the site collection :-
    • SharePoint Server Publishing Infrastructure - Site collection feature-
    • SharePoint Server Publishing - site feature-
  3. then i download the seatle.master master page for the site collection.
  4. I apply some modification to the master page. such as:-
    • i moved the search-box to be on the upper left corner of the page (under the setting gear icon). this is the code which i moved :-
<SharePoint:AjaxDelta id="DeltaPlaceHolderSearchArea" BlockElement="true" CssClass="ms-mpSearchBox ms-floatRight" runat="server"> <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
      <div id="searchInputBox">
        <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />
      </div> </asp:ContentPlaceHolder> </SharePoint:AjaxDelta>
  • i apply a footer.
<div id="customFooter"  class="noindex">&copy; our company name</div>
</div>
</SharePoint:SharePointForm>
  • add the current date time above the search as follow:-

enter image description here

  1. I set the new master page as defualt.
  2. and i went to "site setting>>look and feel>>master page>> i set an Alternate CSS URL".
  3. then under the sit collection, i create a new sub-site of type team site (name it SubSiteA).
  4. then i went back to the site collection "site setting>>look and feel>>master page" i set to reset and apply the master page on all the sub-sites. enter image description here.
  5. So now i have SubSiteA having the same master page customization as in its parent site collection. which is fine till now.

--Problem start here---

  1. now inside SubSiteA , i save the site as template.
  2. and i create a new sub-site (name it SubSiteN) and i chose the above temple.but the problem is that inside the new sub-site SubSiteN which i create based on the template , i note that the master page modifications are not there, while it is referencing the alternate css. For example on the new sub-site (subsiteN), the search box, the date/time and the footer are not there , as follow:-

enter image description here

To force SubSiteN to use the custom master page i need to go back to the site collection and chose to reset the master page for all the sub-sites. but i do not want to keep doing this each time i create a new sub-site based on the template.

so can anyone advice on this please?

Further info. now i checked the master page inside SubSiteN using sharepoint designer and it looks as follow:-

enter image description here

and the _devicechanelmapping file is as follow,where it is correctly referencing the custom.master,, but not sure why the custom master page was not applied correctly on the new subsite which i create based on the template:-

<%@ Reference VirtualPath="~CustomMasterUrlForMapping0" %><%@ Page Language="C#" Inherits="Microsoft.SharePoint.Publishing.Internal.WebControls.MappingsFileBasePage" %><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<head>
<meta name="WebPartPageExpansion" content="full" />
<!--[if gte mso 9]>
<SharePoint:CTFieldRefs runat=server Prefix="mso:" FieldList="FileLeafRef"><xml>

<mso:CustomDocumentProperties>
<mso:ContentTypeId msdt:dt="string">0x010100FDA260FD09A244B183A666F2AE2475A6004CEB6EC65F9F2646A882D81830A08C7E</mso:ContentTypeId>
<mso:FSObjType msdt:dt="string">0</mso:FSObjType>
<mso:Order msdt:dt="string">700.000000000000</mso:Order>
<mso:FileDirRef msdt:dt="string">test22/_catalogs/masterpage</mso:FileDirRef>
<mso:FileLeafRef msdt:dt="string">__DeviceChannelMappings.aspx</mso:FileLeafRef>
<mso:ContentType msdt:dt="string">Device Channel Mappings</mso:ContentType>
<mso:UIVersion msdt:dt="string">15</mso:UIVersion>
</mso:CustomDocumentProperties>
</xml></SharePoint:CTFieldRefs><![endif]-->
</head><body><mappings>
  <defaultChannelMapping>
    <siteMasterUrl token="~sitecollection/_catalogs/masterpage/Custom.master" href="/_catalogs/masterpage/Custom.master" />
    <systemMasterUrl token="~sitecollection/test22/_catalogs/masterpage/seattle.master" href="/22/_catalogs/masterpage/seattle.master" />
    <alternateCssUrl token="" href="" />
    <themedCssFolderUrl token="" href="" isthemeshared="false" />
  </defaultChannelMapping>
</mappings></body></html>

can anyone advice how i can preserve the master page customization inside the site template ?

EDIT 4 December 2016 now i follow the same process as mentioned inside this link

jeffreypaarhuis.com/2011/10/21/your-master-page-automatically-on-newly-created-subsites/

where i mainly did the following steps:

  1. i download the site template from "site setting">>"solutions".
  2. i open the site template inside visual studio.
  3. i modify the ONet.xml file .
  4. where i changed this :-

-

<Configuration ID="0" Name="Default" MasterUrl="/_catalogs/masterpage/seatle.master" CustomMasterUrl="" ThemedCssFolderUrl="">

To reference the custom master page:-

<Configuration ID="0" Name="Default" MasterUrl="/_catalogs/masterpage/Custom.master" CustomMasterUrl="" ThemedCssFolderUrl="">
  1. i rebuild, then publosh the wsp file inside visual studio (where i have define "False" for "Include assembly in project").
  2. i re-upload the updated wsp site template inside my "Site Settings">>"Solutions".

  3. i activate the solution.

  4. i create a new sub-site based on the template. but i got this error on the sub-site home page

"Resource can not be found" enter image description here

  1. so i re-modify the site template inside visual studio and i explicitly define the master page Absolute URL as follow:-

  2. i upload, activate the new solution.

  3. but when i create a new sub-site based on the template, i did not get any error but the custom.master page was not applied!!

so can anyone adivce on this please ?

Thanks

2
+100

Looks like you have spent a lot of time to get this working. I would suggest creating an event receiver which will fire and update the master page after your subsite has been created.

SharePoint has SPWebEventReceiver.WebProvisioned method which will get called after your subsite has been created. The code would be as below for your scenario:

public override void WebProvisioned(SPWebEventProperties properties)
{
        base.WebProvisioned(properties);

        SPWeb web = properties.Web;

        string masterPage="Custom.master";  

        var masterUri = new Uri(web.Url + "/_catalogs/masterpage/" + masterPage);  

        web.MasterUrl = masterUri.AbsolutePath;  

        web.CustomMasterUrl = masterUri.AbsolutePath;  

        web.Update();
}

Usage - Keep your template as it is and write your custom event receiver code and deploy it. You can test it by creating a new subsite using your custom template and check.

Reference - How to Attach an Event Receiver to the Web Added Event And For What Purpose

SPWebEventReceiver.WebProvisioned method

In case you get access denied error, you can just elevate the permission as below:

public override void WebProvisioned(SPWebEventProperties properties)
{
    base.WebProvisioned(properties);


       using(SPSite site = new SPSite(properties.SiteId)
       {
          using(SPWeb web = site.OpenWeb(properties.Web.ID)
          {                   
            string masterPage="Custom.master";  

            var masterUri = new Uri(web.Url + "/_catalogs/masterpage/" + masterPage);  

            web.MasterUrl = masterUri.AbsolutePath;  

            web.CustomMasterUrl = masterUri.AbsolutePath;  

            web.Update();
          }
       }   

}
  • have edited the code now. – Gautam Sheth Dec 5 '16 at 12:24
0

There is no out-of-the-box-solution, so you could create an event receiver that sets the custom master page to every new site.

Alternatively, you can modify the custom site template as described here:

http://jeffreypaarhuis.com/2011/10/21/your-master-page-automatically-on-newly-created-subsites/

  • can you check my edit as the steps inside your yrl did not work – john Gu Dec 4 '16 at 0:28
  • Maybe the reason it did not worked is that you built a new wsp instead of modifying the one you downloaded. You should download the .wsp, modify the extension to .cab, modify the file ONet.xml with the custom master page url, rebuild the .cab and modify the extension to .wsp. Then upload the modified .wsp template in SharePoint. Tell me if it works. – Cecilia Dec 4 '16 at 21:24
0

Once you apply your changes to the master page, you have to publish it as a major version. You can do this by going to the top level site, click on settings gear icon, click Design Manager , from the left navigation pane click on edit master pages, you can find your master page along with the status. If the status says draft, then click on the item options and Publish as a major version. Once the publishing is done, the status changes to conversion successful. Now try to take a site template and check. Let me know if this works out. Cheers !

  • yes the master page is already published as major version.. this is done when i created the custom master page .. before start adding sub-sites and save them as templates.. so i do not think this is the issue – john Gu Nov 25 '16 at 15:06
  • no it did not work, check my above comments// – john Gu Dec 1 '16 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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