Forum Discussion
PapagenoSweden
Nov 08, 2018Copper Contributor
Using Type Script to create a modern page?
I want to create an SPFx webpart that can create a modern page. I've seen code snippets creating modern pages, but it's eighter PowerShell or C# (CSOM or PnP). But I havn't seen any examples on how t...
- Nov 13, 2018
Hi,
Just FYI, PnP JS-Core is deprecated in favor of the new PnPJs libraries.
You can find exactly what you're trying to do (create pages and add components) here:
https://pnp.github.io/pnpjs/sp/docs/client-side-pages/
PapagenoSweden
Nov 13, 2018Copper Contributor
Ok, I got it. A bit embarrassing, but still...
I can of course use the same PnP approach in TypeScript as in C#. I just need to be aware of the async-await concept. This is how you do it:
import pnp,{ClientSideText} from "sp-pnp-js";
protected async CreatePageAsync() {
const page = await pnp.sp.web.addClientSidePage("my page.aspx");
page.addSection().addControl(new ClientSideText("my content"));
await page.save();
}
And then you call the function:
this.CreatePageAsync();
Found the solution https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Client-side-Pages.
Thomas Berman
Nov 13, 2018Iron Contributor
Hi,
Just FYI, PnP JS-Core is deprecated in favor of the new PnPJs libraries.
You can find exactly what you're trying to do (create pages and add components) here:
https://pnp.github.io/pnpjs/sp/docs/client-side-pages/