WebTemplate for 'saved sites a template'
-
29-01-2021 - |
Question
I am using MS Flow to POST a HTTP request to SharePoint to create a Sub site when an item has be entered into a list.
I want to create this sub site using a site template I have saved.
I am trying to figure out the ID for my Sharepoint Site Template but I am not sure where this to find it? I have checked out this site but not able to find anything here:
SharePoint templates and their Ids
Any ideas how to do this?
Solution
There are two ways to find out the TemplateId for custom template:
- Using User Interface:
Go to the site creation page where you selects the custom site template to create new site. Locate the site template you want to use and Press F12 or Right click > Inspect Element.
- Using Programming:
The following code will return WebTemplateId using its site template name:
function CreateSubsiteByTemplateName(templateTitle) {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);
var webTemplates = web.getAvailableWebTemplates(1033, false);
context.load(webTemplates);
context.executeQueryAsync(
function() {
var enumerator = webTemplates.getEnumerator();
var templateId = "STS#0";
while (enumerator.moveNext()) {
var webTemplate = enumerator.get_current();
var webTitle = webTemplate.get_title();
if (webTitle == templateTitle) {
templateId = webTemplate.get_name();
break;
}
}
return templateId;
}, function(sender, args) {
alert(args.get_message())
});
}
References: