Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to create a SharePoint page out of Sharepoint page template using PNPJS #10099

Open
2 of 9 tasks
maxkuzma-munich opened this issue Feb 3, 2025 · 0 comments
Open
2 of 9 tasks

Comments

@maxkuzma-munich
Copy link

maxkuzma-munich commented Feb 3, 2025

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

No response

Issue description

So basically I'm currently trying to create a new sharepoint page from a template page that I have created earlier, all that using PNPJS. The issue is that I cannot find any way to directly create it from the template like I would do in SharePoint when clicking on the New->Page->Saved on this site->and select the template i need. As far as I read the PNPJS documentation, there are 2 ways of making a new page based on the template page:

  1. loading the template page using loadClientSidePage and using copy function to replicate the template page
const templatePage = await sp.web.loadClientsidePage(templatePageURL)
await templatePage.copy(sp.web, newPageName, newPageTitle, true)

the downside of doing it, is that the newly created page is also marked as a template page which I do not need. I tried removing that tag using this approach

// Load the newly created page, and set SitePageFlags to null to remove its 'Template' flag
await sp.web.lists.getByTitle("Site Pages").items.getById(pageId).update({
    OData__SPSitePageFlags: null // Removes the template flag
});

while doing that, sharepoint gives an error that the field is not nullable so I have also tried to set it to [], "", ''. Nothing helped

  1. creating a new page using addClientsidePage, loading the template page, and using copyTo function to copy the contents from template
    this approach is a bit different because it does not copy the entire page but only it's contents, the problem with that is that the newly created page does not replicate the layout of a template page etc. which is essential when creating a page from a template (new page has to be the exact copy of a template page but without being a template itself).

so my question is, is there a way to make an exact copy/create a page using a template page so it is the exact same page as a template without it being flagged as a template too? Maybe there is a way of changing the type of a new created page to normal page insted of it being a template?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant