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.
You may like following SharePoint jsom tutorials:
- Get SharePoint list item by id using jsom (JavaScript object model)
- Uncaught TypeError Cannot read property get_lookupValue of null SharePoint Online JSOM
- How to get workflow template id programmatically using JavaScript Object Model (jsom) in SharePoint
- Delete all items from SharePoint list programmatically using JSOM
- Uncaught ReferenceError: web is not defined Error in SharePoint Online JSOM
- How to get SharePoint person or group field using javascript (jsom)
- Retrieve SharePoint list items programmatically using jsom, rest api and csom
- How to create a list using jsom (JavaScript object model) in SharePoint?
- Retrieve all users from all groups using jsom in SharePoint
- Display SharePoint List Items in Div using JSOM (javascript object model)
In this SharePoint tutorial, we learned how to check which site template used in SharePoint Online Site using JSOM (JavaScript Object Model).
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com