How To Create Custom Create News Button In SharePoint Online

Recently we were developing custom news webpart using SPFx. The functionality was required same as OOTB news webpart. The only change we needed was a few more layout options as well. We need to showcase few more columns details in the news webpart. We build the remaining things as expected but we didn’t have any idea on how to provide create post button as OOTB news webpart provides.

Issue

So, our first approach was the lazy one. We find out a URL that will create a site page and we will train user to click “Promote as news” once the page is published.

URL – [SiteURL]/_layouts/15/CreateSitePage.aspx

But the issue is, Client didn’t agree on having a 2 click solution.

Solution

We got a blog from Shantha Kumar (link in description) that provided us an initial idea on the difference between modern site page and news post. Microsoft has put a parameter – “Promoted State” to differentiate the page creation.

Promoted State Page Creation Experience
0 or null This will create Modern Site page
1 This will create News post in draft version.
2 This will be the News Post in published version.

In simple terms, if we hit below URL, it will create the news post, [SiteURL]/_layouts/15/CreateSitePage.aspx?promotedstate=1

This solved the first half of the issue. But Microsoft has provided different experience in news post creation. If you are creating news post from site pages, it will create post from basic template directly. But if you are creating it from home page or any news post, it will showcase template selection.

Client asked us if it is possible to open that pane from button click. Here we needed to research some more and ultimately our saviour stack exchange has answer for that. The updated URL will look like below:

[SiteURL]/_layouts/15/CreatePageFromTemplate.aspx

As the information is scattered and hidden, I thought it would be useful to have this in one place. Hope this helps.

Reference: