5

Is there a way to check if the current page is a Wiki page or a Publishing Page using Client side methods in SharePoint 2013.

5

Use the PnP JavaScript Library to check the page type.

We can determine the Page type by using Content Type Id,

  • Wiki Page - content type id starts with "0x010108"
  • Web Part page - Content type id starts with "0x010109"
  • Publishing Page will have the Property called PublishingPageLayout field.

Example 1: ( Determine based on Content type id)

$pnp.sp.web.getFileByServerRelativeUrl("/Pages/PublishingPage.aspx").listItemAllFields.select('ContentTypeId,PublishingPageLayout').get().then(function(data) {
    if (data.ContentTypeId.startsWith("0x010108"))
        console.log('Wiki Page');
    else if (data.ContentTypeId.startsWith("0x010109"))
        console.log('Web Part Page');
    else {
        if (data.PublishingPageLayout != undefined)
            console.log('Publishing Page');
        else
            console.log('Others');
    }

});

Example 2: (Determine based on Page Field name)

$pnp.sp.web.getFileByServerRelativeUrl("/sitepages/testpnp.aspx").listItemAllFields.select('wikiField,PublishingPageLayout').get().then(function(data) {
    if (data.WikiField != undefined && data.WikiField != null)
        console.log('Wiki Page');
    else if (data.PublishingPageLayout != undefined)
        console.log('Publishing Page');
    else
        console.log('Nor wiki or Publishing Page');

});

To run the above code in on-premise environment, add the below code to the top of above examples,

$pnp.setup({
    headers: {
        "Accept": "application/json; odata=verbose",
    },
});

To know more about PnP JS library, click https://github.com/OfficeDev/PnP-JS-Core

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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