2539 Views
2 minute read
Categories
SharePoint Custom Development

Limiting The Custom Web Templates

Overview

You are using SharePoint 2013 On-Premises. You want to be able to filter the Site Templates that users see when the user tries to create a sub site. As Site administrator you can do this by navigating to Site Setting> Page layouts and site templates.

P1

In this blog I will explain how you can implement the same capabilities via the code.

Limiting Custom Web Templates using CSOM

Removing all OOTB Filter Tabs using JQuery 

  • Site creation page is a regular application layout page NewSbWeb.aspx located in _layouts/15 folder on file system of web server. So you can modify this page by hiding template picker control which is InputFormTemplatePickerControl
  • Need to hide the OOTB Filter Tabs so that end user won’t be selecting any tabs
  • Remove the existing OOTB Filter Tab options
var hiddenFieldElement = $("input[id*='InputFormTemplatePickerControl']");

hiddenFieldElement.next().children().remove();

var select = hiddenFieldElement.next().next();

var opts = select.find('option');

opts.each(function(){

$(this).remove();

});

Get All Available Templates of the site collection and add only Custom Web Templates

  • Get All Available Templates of the site collection using  GetAllAvailableTemplates Method
//getting all available web templates from root web

templateCollection = web.getAvailableWebTemplates(1033, false);
  • Filter only the Custom Web Templates required
  • Add only the custom Web Templates needed to InputFormTemplatePickerControl which displays the Template
var templatePicker = $("input[id*='InputFormTemplatePickerControl']").next().next();

while(siteTemplatesEnum.moveNext())

{

var siteTemplate = siteTemplatesEnum.get_current();

if (siteTemplate.get_name().toUpperCase().indexOf("CUSTOM") != -1)

{

Templates +=  siteTemplate.get_name() + "----"  + siteTemplate.get_id() +   ',';

sitename = siteTemplate.get_name().substring(siteTemplate.get_name().indexOf("#")+1);

templatePicker.append("<option value='" + siteTemplate.get_name() + "'>" + sitename + "</option>");

}

}

templatePicker.prop("selectedIndex",0); //selecting the first option

//This is to hide the WebTemplate Label which shows the description of the OOTB web templates

var webtemplatelabel = $("input[id*='InputFormTemplatePickerControl']").next().next().next();

webtemplatelabel.hide();

}
Jubaraj Pandit

About Jubaraj Pandit

Experienced Principal Engineer with a demonstrated history of working in the computer software industry. Skilled in SharePoint 2013 Online, .Net, MVC, SQL Server Reporting Services (SSRS), Microsoft Word, jQuery, ASP.NET AJAX, and English. Strong engineering professional with a Master of Computer Applications (MCA) focused in Computer Programming, Specific Applications from IGNOU.

LinkedinTwitterFacebook

1 reply on “Limiting The Custom Web Templates”

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :