Code to get all site templates both inbuilt and custom site template ID using CSOM.
var templateCollection ;
function GetWebTemplates()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
templateCollection = web.getAvailableWebTemplates(1033, false);
context.load(templateCollection);
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var Templates = "";
var siteTemplatesEnum = templateCollection.getEnumerator();
while(siteTemplatesEnum.moveNext())
{
var siteTemplate = siteTemplatesEnum.get_current();
Templates += siteTemplate.get_name() + ',';
}
alert("Site Templates - " + ',' + Templates);
}
function failed(sender, args) {
alert("Failed");
}
var templateCollection ;
function GetWebTemplates()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
templateCollection = web.getAvailableWebTemplates(1033, false);
context.load(templateCollection);
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var Templates = "";
var siteTemplatesEnum = templateCollection.getEnumerator();
while(siteTemplatesEnum.moveNext())
{
var siteTemplate = siteTemplatesEnum.get_current();
Templates += siteTemplate.get_name() + ',';
}
alert("Site Templates - " + ',' + Templates);
}
function failed(sender, args) {
alert("Failed");
}
While you can get all the inbuilt site template ID from below link
And custom site template would have a format like this.
{GUID}#TemplateName
No comments:
Post a Comment