Tuesday, February 17, 2009

How do I save a publishing site as a template?

You may have noticed that the “Save site as template menu” under “Look and Feel” site settings category is missing. This brings one to ask:
How do I get it back? And more importantly: Why was it removed?
In the following article I will answer these questions and give you tools to address this issue on your own.

Background

In WSS sites, when you go to site settings page, this is how your “Look and Feel” category looks:


Notice you have the “Save site as template” menu option there.
It is important to understand that everything in SharePoint 2007 is based on features. So – you would be correct to assume this menu option is also a feature:
Feature folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\SiteSettings
Feature file: SiteSettings.xml
Definition:
<customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60"><customaction id="SaveAsTemplate" title="$Resources:SiteSettings_SaveAsTemplate_Title;" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" rights="AddAndCustomizePages,BrowseDirectories,ManagePermissions,ManageSubwebs,ManageWeb,UseRemoteAPIs,ViewFormPages" sequence="60">
<urlaction url="_layouts/savetmpl.aspx">
</customaction></customaction>
<urlaction url="_layouts/savetmpl.aspx"></customaction><urlaction url="_layouts/savetmpl.aspx"></customaction>
<urlaction url="_layouts/savetmpl.aspx"></customaction><urlaction url="_layouts/savetmpl.aspx"></customaction><urlaction url="_layouts/savetmpl.aspx"></customaction>

When you create a publishing portal site (internet facing or intra net collaboration portal) you will notice that among other changes, the “Look and Feel” site settings category has changed, a lot:


Notice, there is no longer the option to "save site as template".

So, keeping in mind that everything in SharePoint is controlled by features – think of a publishing site as a normal WSS sites that had some features activated in it (*this is not 100% accurate, but as it simplifies things we will say so, for the sake of the example).
Looking further in our Feature folder, you will easily find several feature folders that belong to the publishing site. One of these features calls you to hide the save as template menu from the site settings:

Feature folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\Publishing
Feature file: PublishingSiteSettings.xml
Definition:
<hidecustomaction id="HideSaveAsTemplate" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" hideactionid="SaveAsTemplate"><hidecustomaction id="HideSaveAsTemplate" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" hideactionid="SaveAsTemplate"><hidecustomaction id="HideSaveAsTemplate" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" hideactionid="SaveAsTemplate"><hidecustomaction id="HideSaveAsTemplate" location="Microsoft.SharePoint.SiteSettings" groupid="Customization" hideactionid="SaveAsTemplate">

Notice the use of the HideCustomAction tag, with the corresponding HideActionld “SaveAsTemplate”.

Why is the “Save site as template” menu option removed from publishing sites?


Many of my customers use publishing sites. A lot of them tried to use the save as template option (some using code, some using a feature like the one below) and we all came to the same conclusion:
Since publishing sites have pages in them and layouts that are all connected to a content type that is configured at the top level site of the site collection, and because these content types are not saved and moved within the site template STP file – the STP file not, as one would expect it to be, a true reflection of the original site.
This means that if you save a publishing site as template and use it in the same site collection, providing all site content types it uses remain unchanged, the site template will work properly.
The problem arises when you try to move the site template to a different site collection, or when you've changed or deleted some content types in your current site collection – this will result in unexpected behaviour (that from my experience is irritating but fixable, with some work).
So, if you want to use the site templates within the same site collection, or if you use only the out of the box content types (welcome and article) with no changes, you should have no difficulties.

How do I add the “Save site as template” option back to publishing sites?


Here is what you need to do to add this option back to your publishing site. It's very simple; it will take approximately five minutes of work!
Simply create, install and activate a feature that will bring this menu option back to life!

Create feature
Create a feature that re-registers a “save as template” action to site settings. I said 5 minutes, right? So here is a feature ready to use (it's my free gift to you! ;)
Save the folder inside the ZIP file, under your server’s features folder.

Install Feature
Run STSADM command:

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm" -o installfeature -name AddSaveTemplateToPublishingSiteSettings –force

Activate Feature
After installation, you should have this new site collection feature:


Result
If you did everything correctly, your new publishing site settings “Look and Feel” section will appear like this:


You will now be able to "save site as template".
Easy, huh?!

* There may be other side effects of saving a publishing site as template. This article is for the community information benefit only and will not hold KWizCom responsible to any issues caused by this. It is strongly recommended you test on a pre production environment before you use this tip in a production server.

6 comments:

Unknown said...

Or if you're in a hurry or don't have access to deploy features then just put "_layouts/savetmpl.aspx" after the site URL. Seemed to work for me.

Shai Petel said...

LOL Darrin... you are correct!

Anonymous said...

"_layouts/savetmpl.aspx"
not good for SP2010. can create a template, but not to create a site based on it.

Shai Petel said...

True, since STP's are no longer supported in 2010.

Perhaps we should make a tool that reads the STP and make a site off it in 2010? I'll look into it... see what is involved. Lots of people still have STPs from older solutions I am sure.

Anonymous said...

Did you ever create a tool reads the STP and make a site off it in 2010?

Shai Petel said...

I have not,
seems like it requires several steps. the easiest one is to recreate a new template in 2010 after upgrading a 2007 site.

I found several scripts that can help with that on the web but i would not trust any of these steps if i were you.

I would upgrade a 2007 site, and save it as a new tempalte. this seems to be the only 100% supported way.

Sorry.