I'm configuring a custom search results page in a test environment and one of the things we can customize is the layout for our new results page, to get rid of all the chrome. To do this, we can use the SharePointPnPPowerShellOnline PowerShell module, in particular the
Set-PnPClientSidePage command, as follows (Results.aspx is of course the test results page I created):
Set-PnPClientSidePage -Identity "Results.aspx" -LayoutType HeaderlessSearchResults
However, when I run the command (which runs without error) and visit the page, I get the following error screen:
Now, I didn't immediately recognise this 'We can't show this page with its current layout' eror, and I really didn't want to log a call to Microsoft for this with that correlation id, as this seemed much easier to solve, so I started with some web searching, but found nothing under the error text itself, so I started broadening my search and looked for 'HeaderlessSearchResults' instead. When I did so, this link to the SharePoint dev docs on GitHub came up, and inside @PatMill suggested trying to search the source code in the page for that error. When I visit my original page, however, it immediately redirects to the Error page, much as Sébastien pointed out in the next comment.
So, time to fire up Fiddler! I did so, and in the html for my original page, I see a reference to the following js file:
Inside this file, when I did a search for 'We can't show this page with its current layout', I find the following object:
unsupportedScenarioTitle:"We can't show this page with its current layout",
unsupportedScenarioDescription:"This page has a layout that only works when it is used as a search results page. To set this page as the search results page, go to Search Settings for this site collection, and set this page as the Results Page URL. You can also change its layout back to another one that's supported to view it."
And bingo I have an error I can work with! It turns out I hadn't set this page as the Search Results page for anyone yet. If I do so in the demo site I'm using, it works!
To do this, go to the site settings, then "Search Settings" (in this case I want it to apply to the entire site collection, so I go to the "Search Settings" inside the Site Collection Administration section) and I set my page as the Search Results page, as follows:
When I hit the Save button and refresh my page, it's working as per below:
Hope that helps someone with the same issue.