I'm trying to create a publishing page following this thread and the page is being created in the library. Basically using creating a template
<%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=126.96.36.199,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %><%@ Reference VirtualPath="~TemplatePageUrl" %><%@ Reference VirtualPath="~masterurl/custom.master" %>
and then sending that as the body to this REST endpoint
/_api/Web/GetFolderByServerRelativeUrl('Pages')/Files/add(url='" + pageName + ".aspx',overwrite=true)
This creates a page, but doesn't have the correct page layout or content type.
I tried using REST to set the pagelayout and it didn't throw an error, but it also didn't work. I found this thread which shows how to set the page layout via JSOM. I chain it with my REST call to get the docId of the new page and then call this:
var ctx = SP.ClientContext.get_current(); var listPages = ctx.get_web().get_lists().getByTitle('Pages'); var pageItem = listPages.getItemById(docId); var val = new SP.FieldUrlValue(); val.set_url('_catalogs/masterpage/PageLayouName.aspx'); val.set_description('PageLayoutName'); pageItem.set_item('PublishingPageLayout', val); pageItem.update();
That works and does change the page layout for the page. When I open the page for editing I see the metadata associated with the contenttype for the page layout and I see the various webpart zones as defined for my page layout. The pagelayout has several zones, page fields, content query webpart, etc. It almost seems to work, except...
In my page layout I have a content editor webpart snippet defined. That webpart doesn't show on the page. The zone it is in is there but the webpart just isn't there.
If I reapply the page layout from the UI using the ribbon the missing webpart shows up.
How can I create a page that properly uses its page layout?