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=,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();
pageItem.set_item('PublishingPageLayout', val);

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?

1 Answer 1


If your CEWP is inside a WebPart zone into your Page Layout, it will be ignored when you apply the layout to your newly created page.

You have 2 options:

  1. Edit the page layout and put your CEWP outside the WP zone. Then the CEWP will be available on all pages and couldn’t be removed afterwards on pages
  2. Provision your CEWP by CSOM/JSOM code using LimitedWebpartManager.AddWebpart (sample usage)

Hope it will help you.

  • So option 2 is not available client side? We are only site collection admins and don't have access to anything server side.
    – Rothrock
    Oct 29, 2019 at 14:37
  • Of course it’s available, you have a sample provided by Microsoft here: docs.microsoft.com/en-us/previous-versions/office/developer/… Oct 29, 2019 at 14:49
  • I tried moving the CEWP outside the WP Zone. Whether created through the UI, my code, or existing pages the CEWP is not editable by end users. We don't want users to be able to delete it from the page, but they do need to be able to add text. I'll look at the sample.
    – Rothrock
    Oct 29, 2019 at 14:59
  • Exact, i forgot to say the option 1 will not let end users the ability to change settings. So the option 2 would more suitable for you. Oct 29, 2019 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.