Exclude SharePoint online modern page templates from search results

In this short blog post we will look at how to exclude the modern page templates from search results in SharePoint online.

Introduction

Page template is a great feature in SharePoint online and helps users save a lot of time. In some scenarios, for example — rolling up site pages in a web part, we might have to exclude these page templates as it wouldn’t make sense to display them in such scenarios.

Options to exclude page templates

If we are using SharePoint REST API to get the site pages, then we can add the filter OData__SPSitePageFlags ne "Template" to our query. The details of this property is explained in detail by Beau Cameron in this blog post.

If we are using SharePoint search to get the site pages, then we have a couple of options to exclude page templates

With this option we can exclude the “path” of the templates folder in our search query. This can be done by adding -Path:"https://yourtenant.sharepoint.com/sites/yoursite/sitepages/templates" . This will exclude all the pages under the “templates” folder in “Site Pages” of a given site.

As mentioned in Beau’s blog post there is an internal column called “OData__SPSitePageFlags” which will have the value as “Template” for a page template. The corresponding managed property for this column is “SitePageFlags”. By adding -SitePageFlags:"Template" to our search query, we can exclude all the page templates in our search results.

Microsoft MVP. M365 Developer Architect at Content+Cloud.