Sometimes, there are situations when we need to identify Template Id that we have created for custom template.

SharePoint

Suppose, I created Team Site. When I save that site as Template, it will be shown to me in “Custom Templates” field everytime I create a new site/subsite.

There are two ways to find out the TemplateId for custom template.

  1. Using User Interface
  2. Using Programming

Way 1 : Using UI

Step 1

Press F12 or Right click > Inspect Element.

Step 2

You will find its Custom TemplateId easily.

SharePoint

Way 2 : Using Programming

There are some situations when we have to find TemplateId programmatically using TemplateName.

In that situation, what should we do?

Well, here is a solution. The following code will return WebTemplateId using its name.

Below is a description for parameters.

templateTitle = Name of a custom Template which we want to find out.

Ex

Suppose we want to find out Template ID for “Custom Template 2”. Then, pass the value for templateTitle = “Custom Template 2”.

  1. function CreateSubsiteByTemplateName(templateTitle) {
  2. var context = new SP.ClientContext.get_current();
  3. var web = context.get_web();
  4. context.load(web);
  5. var webTemplates = web.getAvailableWebTemplates(1033, false);
  6. context.load(webTemplates);
  7. context.executeQueryAsync(function() {
  8. var enumerator = webTemplates.getEnumerator();
  9. var templateId = "STS#0";
  10. while (enumerator.moveNext()) {
  11. var webTemplate = enumerator.get_current();
  12. var webTitle = webTemplate.get_title();
  13. if (webTitle == templateTitle) {
  14. templateId = webTemplate.get_name();
  15. break;
  16. }
  17. }
  18. return templateId;
  19. }, function(sender, args) {
  20. alert(args.get_message())
  21. });
  22. }

The above function will return TemplateId for custom template.

Please let me know if you have any questions.

1 Comment

Join the conversation! Your thoughts help the community grow.

  • How to find a custom template name which is used in sharepoint site?