How to check which site template used in SharePoint Online Site using JSOM (JavaScript Object Model)?

This JSOM tutorial explains, how to retrieve or check site templates used in the SharePoint Online site using jsom (JavaScript Object Model).

Here we will write our jsom SharePoint online code using a script editor web part. You can also use the content editor web part in SharePoint Online. We will display the value on page load as well as on a button click using jQuery and jsom.

To add a script editor web part, we need to first create a web part page in SharePoint Online.

Retrieve site template used in SharePoint Online site using jsom (On Page Load)

Here we will see how to retrieve site template sued in a SharePoint Online site template using JSOM on page load.

<h2>Retrieve Site Templates used in SharePoint Online site On Page Load</h2>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="ptemp"></p>
<script>
ExecuteOrDelayUntilScriptLoaded(retrieveSiteTemplate, 'sp.js');
var site;
function retrieveSiteTemplate() {
var clientContext = new SP.ClientContext.get_current();
site = clientContext.get_web();
clientContext.load(site);
clientContext.executeQueryAsync(success, failure);
}
function success() {
$("#ptemp").html("Site Template Used:: "+ site.get_webTemplate());
}
function failure() {
alert("Failure!");
}
</script>

Retrieve site template used in SharePoint Online site using jsom (On Button Click)

Now, we will see how to retrieve site template used in SharePoint Online site using JSOM on a button click.

<h2>Retrieve Site Templates used in SharePoint Online site On Button Click</h2>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" value="Retrieve Site Template" id="btnClick">
<br/>
<p id="ptemp"></p>
<script>
$(document).ready(function(){
$("#btnClick").click(function(){
retrieveSiteTemplate();
});
});
var site;
function retrieveSiteTemplate() {
var clientContext = new SP.ClientContext.get_current();
site = clientContext.get_web();
clientContext.load(site);
clientContext.executeQueryAsync(success, failure);
}
function success() {
$("#ptemp").html("Site Template Used:: "+ site.get_webTemplate());
}
function failure() {
alert("Failure!");
}
</script>

Once you save the code and click on Button, you can see it will show the list template used in the SharePoint Online site.

retrieve site template used for site in sharepoint online
retrieve site template used for site in sharepoint online

You may like following SharePoint jsom tutorials:

In this SharePoint tutorial, we learned how to check which site template used in SharePoint Online Site using JSOM (JavaScript Object Model).

>