none
Team Site master page Inheritance RRS feed

  • Question

  • I have a root site collection that is a team site and I set the master page in SPD, using the Set as Default and Set as Custom buttons. When I create a new site under the root team site it doesn't use the custom master page.

    My understanding is that feature stapling no longer works in 2013.

    I created a template site, set the master page by manually navigating to {site}/_layouts/15/ChangeSiteMasterPage.aspx. Saved the site as a template. Created a new site using the saved template, still no dice, its using OOB site template.

    The behavior I would like to see would be similar to Publishing Site, that any site created under a given site would inherit its Master Page look and feel. Any advice or lit on how to distribute and default a custom master page would be helpful.

    Thanks in advance.

    Wednesday, July 24, 2013 3:21 PM

Answers

  • Hi Jeremy,


    I din't realize that you were using a custom site template. So, feature stapling will not work. An alternate way to ensure all your child sites use the same master page is to use an event reciever which gets fired when a new subsite gets created. That is - WebProvisioned Event Receiver. Use the same code I mentioned in my earlier post in your event reciever so that it auto applies the same master page to any new child site.

    See the following link also -

    http://stefan-stanev-sharepoint-blog.blogspot.com/2010/09/webprovisioned-event-receiver-practical.html

    Narahari

    ******If a post answers/helps your question, please click "Mark As Answer" on that post and/or "Vote as Helpful*******

    Monday, July 29, 2013 7:47 PM

All replies

  • Hi Jeremy,

    Feature stapling does work in SP 2013. Create a simple stapler feature which will use the parent master page as follows -

    using (SPWeb parent = web.ParentWeb)
                        {
                            web.AllowUnsafeUpdates = true;
                            web.MasterUrl = parent.MasterUrl;
                            web.CustomMasterUrl = parent.CustomMasterUrl;
                            try
                            {
                                web.SiteLogoUrl = parent.SiteLogoUrl;
                            }
                            catch (Exception ex) {
    //Your custom logic
     }
                            web.Update();
                            web.AllowUnsafeUpdates = false;
                        }

    Tie the stapler feature to the required site definitons and it should work.

    Also, manually if you go to Site settings -> Master Page and select the checkboxes for resetting the subsites to use this master page and system master page, it automatically applies the same branding to the subsites.

    Hope it helps :-)

    Narahari

    *******If a post answers your question, please click "Mark As Answer" on that post and/or "Vote as Helpful *********


    Wednesday, July 24, 2013 4:53 PM
  • //Also, manually if you go to Site settings -> Master Page and select the checkboxes
    //for resetting the subsites to use this master page and system master page, it
    //automatically applies the same branding to the subsites.

    I'm familiar with this but it doesn't help meet my business requirement. I need the sub sites automagically inherit the master page, similar to the way publishing sites do.

    I build the feature staple and deploy it and get back to you.

    Thanks again!


    • Edited by Jeremy Allen Bond Wednesday, July 24, 2013 6:29 PM adjusting quoted comment
    Wednesday, July 24, 2013 6:27 PM
  • Yep, That worked. Thanks!

    Something else I noticed though, its not applying to custom site templates. Even if I set TemplateName="Global", no dice.

    Then I fond this comment over at - http://msdn.microsoft.com/en-us/library/bb861862(v=office.12).aspx

    Custom Site Templates        
                 Feature stapling does not apply to custom site templates. WSS SDK has been updated as well regarding this.        

    So~ is there another way to apply my master page to custom site templates besides Feature Stapling?
    Saturday, July 27, 2013 5:19 AM
  • Can we try creating webprovisioned event receiver and activate feature in the event. 

    So, Steps could be

    1) Create a WebProvisioned Event Receiver

    2) In the Event receiver, use the same logic as 

    web.MasterUrl = parent.MasterUrl;
    web.CustomMasterUrl = parent.CustomMasterUrl;

    3) Use a Feature to deploy the event receiver and activate this feature on root site. 

    Thanks,

    Ved

    Saturday, July 27, 2013 5:58 AM
  • Ved, not tracking you here. Sounds like you're describing stapling, No?
    Monday, July 29, 2013 3:40 PM
  • Hi Jeremy,


    I din't realize that you were using a custom site template. So, feature stapling will not work. An alternate way to ensure all your child sites use the same master page is to use an event reciever which gets fired when a new subsite gets created. That is - WebProvisioned Event Receiver. Use the same code I mentioned in my earlier post in your event reciever so that it auto applies the same master page to any new child site.

    See the following link also -

    http://stefan-stanev-sharepoint-blog.blogspot.com/2010/09/webprovisioned-event-receiver-practical.html

    Narahari

    ******If a post answers/helps your question, please click "Mark As Answer" on that post and/or "Vote as Helpful*******

    Monday, July 29, 2013 7:47 PM
  • Let me test it out and I'll get back to you.

    Thanks again!
    Tuesday, July 30, 2013 3:59 PM
  • Hi Jeremy, 

    Sorry, if i was not clear. 

    I was not describing feature stapling, instead, i was talking about Web Provisioned Event receiver. And the code inside feature event handler. 

    Now, you have got detailed explanation from Narahari below (If this works for you, Did i miss my points for correct answer? I guess yes ;) )

    Cheers!

    Ved

    Tuesday, July 30, 2013 9:12 PM