Shantha Kumar T
Enable / Disable Master Page Customization in Site Collection
SharePoint has lot of features that can handle through using various api options (SSOM, JSOM, CSOM, REST API, UI, and PowerShell). Here we are going to use JSOM code snippet as an option to enable or disable master page customization for the Site Collection.
Properties Used: SP.Site.allowMasterPageEditing (SP.js)
Supports: SharePoint Online, SharePoint 2010+
SP.Site.get_allowMasterPageEditing | Used to get the Boolean value, whether the master page customization is allowed on the site collection |
SP.Site.set_allowMasterPageEditing(true) | Enables the access to users (Site Owners / Designers) to customize the Master Pages on Site collection level. |
SP.Site.set_allowMasterPageEditing(false) | Disables the access to users (Site Owners / Designers) to customize the Master Pages on Site collection level |
Note: This property doesn’t affect the Site Collection Administrators. They always have access to customize the master pages and page layouts across the site collection.
Get Master Page Customization:
The below example retrieves the value of master page customization is allowed on the current site collection.
[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowMasterPageEditing (sp.js)
//Supports SharePoint 2010 + and SharePoint Online
function getMasterPageAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();
clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of master page editing is allowed on this site collection
if (oSite.get_allowMasterPageEditing())
siteInfo = ‘MasterPage customization: Allowed’;
else
siteInfo = ‘MasterPage customization: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}
function injectMethod() {
getMasterPageAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
[/code]
Code also available in github
Enable Master Page Customization:
The below example enables the access to users to edit / update the master pages and page layouts in the current site collection level.
[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowMasterPageEditing (sp.js)
//Supports SharePoint 2010 + and SharePoint Online
function enableMasterPageAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();
//The below line helps to enables the master page access
oSite.set_allowMasterPageEditing(true);
clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of master page editing is allowed on this site collection
if (oSite.get_allowMasterPageEditing())
siteInfo = ‘MasterPage customization: Allowed’;
else
siteInfo = ‘MasterPage customization: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}
function injectMethod() {
enableMasterPageAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
[/code]
Code also available in github
Disable Master Page Customization:
The below example disables the access to users to edit / update the master pages and page layouts in the current site collection level.
[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowMasterPageEditing (sp.js)
//Supports SharePoint 2010 + and SharePoint Online
function disableMasterPageAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();
//The below line helps to disable the master page access
oSite.set_allowMasterPageEditing(flase);
clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of master page editing is allowed on this site collection
if (oSite.get_allowMasterPageEditing())
siteInfo = ‘MasterPage customization: Allowed’;
else
siteInfo = ‘MasterPage customization: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}
function injectMethod() {
disableMasterPageAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
[/code]
Code also available in github