Pages

5/17/2010

SharePoint: How to Hide a Site Template in Single Site Collection

(this is for SP 2007, not tested with 2010)

 

Here’s a quick little “hack” to hide a template in “Site Actions, Create, Sites and Workspaces” for just a single site. This does require access to the web front end servers.

 

Steps:

  1. In ...\12\TEMPLATE\LAYOUTS find newspweb.aspx and open it in Notepad or your favorite editor.  (you may want to backup this file first!)
     
  2. Just before last line of the file ("</asp:content>") add the following JavaScript
     
  3. In the JavaScript edit the "if (window.location" line for your site collection
     
  4. Also edit the "if (selList.options[i].value==" line for the template IDs(*) you want to hide
     
  5. Copy this page to each of your web front end servers

Notes: This will not survive an upgrade to SharePoint 2010 and would have to be repeated after the upgrade. This should be added to any “rebuild” documentation such as a Disaster Recovery Plan.

(*) for a list of template IDs see here: http://www.devexpertise.com/2009/02/06/sharepoint-list-template-ids-and-site-template-ids/

 

 
<script> 
 
// change this line for your site collection
if (window.location.href.indexOf('/sites/training/')>-1)
{
  // remove items loaded with the page load
  removeitem();  
 
  // remove items loaded with a tab click
  var oldClientCallback = ClientCallback
  ClientCallback = function(result,context)  
  {
    oldClientCallback(result,context)
    removeitem()
  } 
 
  function removeitem()
  {
    var selList = document.getElementById("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl00_LbWebTemplate")
    for (var i=0;i<selList.length;i++)
    {
      // update this line with your template IDs
      if (selList.options[i].value=="STS#0" | selList.options[i].value=="MPS#1")
      {
        try
        {
          selList.remove(i) 
        }
        catch (err) {}
        break;
      }
    }
  }
} 
 
</script> 
 

 

 

This follow is the same as the above, but may be easier to copy and paste…

<script>

// change this line for your site collection
if (window.location.href.indexOf('/sites/training/')>-1)
{
  // remove items loaded with the page load
  removeitem(); 

  // remove items loaded with a tab click
  var oldClientCallback = ClientCallback
  ClientCallback = function(result,context) 
  {
    oldClientCallback(result,context)
    removeitem()
  }

  function removeitem()
  {
    var selList = document.getElementById("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl00_LbWebTemplate")
    for (var i=0;i<selList.length;i++)
    {
      // update this line with your template IDs
      if (selList.options[i].value=="STS#0" | selList.options[i].value=="MPS#1")
      {
        try
        {
          selList.remove(i)
        }
        catch (err) {}
        break;
      }
    }
  }
}

</script>

No comments:

Post a Comment

Note to spammers...
Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.