Exclude SharePoint online modern page templates from search results

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

SharePoint REST API

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.

SharePoint search

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

Option 1 — Excluding the “templates” folder (not preferred)

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.

Option 2 — Using the “SitePageFlags” managed property (preferred)

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anoop

Anoop

154 Followers

Microsoft MVP. M365 Developer Architect at Content+Cloud.