Setting Default Page Layout, Available Page Layouts, and Available Web Templates via CSOM (JSOM)
The publishing infrastructure provides a site with many features including page layouts. A default page layout, a restricted set of available page layouts, and a restricted set of web templates can be set. The page in the UI looks like this:
In order to perform these configurations programmatically, methods are provided as part of the the server side object model via the PublishingWeb object. However setting these properties via CSOM is less obvious. The equivalent methods are not available (at least not at the time of writing. It is worth noting that the CSOM model gets extended as part of CUs as well as in SPO).
The property information is stored solely as web properties. I have verified this by reflecting the Microsoft.SharePoint.Publishing assembly, and ensured that the server side object model methods perform no other action than this.
The following JSOM code demonstrates how to set the web properties with valid XML values.
The methods can be called like this:
// The page layout is defined by its filename
var filename = "NewsArticlePage.aspx";
setDefaultPageLayout(filename, onSuccess, onFailure);
// The page layouts are defined by an array of filenames
var filenames = ["NewsArticlePage.aspx"];
setAvailablePageLayouts(filenames, onSuccess, onFailure);
// The web templates are defined by their long name,
//the guid is that of the feature which deploys the web template
var webTemplates = ["{BDACFFF5-05DF-4446-9907-B4C39F15F1D7}#WT_VanitySite"];
setAvailableWebTemplates(webTemplates, onSuccess, onFailure);
Note – these samples reference both the jQuery and underscore libraries.
As a developer my professional interests are technical and tend to be SharePoint focused. I've been working with SharePoint since 2009 and hope my posts will give back a little to the community that's supported me over this time. I'm also a keen runner (half-marathon) and passionate Brompton bicycle owner.
View all posts by Paul Ryan
4 thoughts on “Setting Default Page Layout, Available Page Layouts, and Available Web Templates via CSOM (JSOM)”
Woah! I’m really diggng the template/theme of this blog. It’s simple, yet effective.
A lot of times it’s difficult to get that “perfect balance” between superb
usability and appearance. I must say you have done a awesome
job with this. In addition, the blog loads extremely fast for me on Safari.
Exceptional Blog!
Thanks! Your PowerShell rendition of this is good stuff.
(For anyone wanting to achieve what is described here in PowerShell see the Pingback in the comments below)
Woah! I’m really diggng the template/theme of this blog. It’s simple, yet effective.
A lot of times it’s difficult to get that “perfect balance” between superb
usability and appearance. I must say you have done a awesome
job with this. In addition, the blog loads extremely fast for me on Safari.
Exceptional Blog!
nice post mate!
Thanks! Your PowerShell rendition of this is good stuff.
(For anyone wanting to achieve what is described here in PowerShell see the Pingback in the comments below)