Tuesday, July 22, 2014

Custom Search Result Page Layout in SharePoint

You’re messing with the search result page and figure you need a new zone on the page for some cool web parts.

Being an avid SharePoint Designer fan as I am, you open up the site and copy _catalogs/masterpage/SearchResults.aspx to _catalogs/masterpage/SearchResults_custom.aspx. Then you add a new web part zone to the bottom of the page and save the layout.

Next you make the layout available on your site (Bing it) and create a new page based on the layout.

Boom! – Code blocks are not allowed


Turns out the fix is pretty easy as the file actually has code blocks in it.


Simply remove the <% %> parts which does conditional checks for the Ribbon being hidden if the user is in Browser mode (not Design, Catalog or Edit mode)

You can probably implement the check yourself in JSOM if needed, or simply show/hide the ribbon in all modes.

So, how come the default layout works with code blocks? Well.. SharePoint does whatever it wants with the default pages and can configure SharePoint to work as it pleases. Being an outsider you don’t have those powers.


  1. I'm not sure if my previous comment made it, so here goes attempt 2.

    I tried creating a custom layout for a search results page, copying the ootb one. For some reason that one has 'Master Page' for content type, so I had to switch that to Page Layout in order to allow the lay-out in my search-center site. I switched it back again, the page remains allowed so it seems.

    Now when I leave the layout alone and create a new results page, everything works. But as soon as I edit the page and save it (don't have to change a thing), the following error pops up: The base type 'Microsoft.Office.Server.Search.Internal.UI.SearchResultsLayoutPage' is not allowed for this page. The type Microsoft.Office.Server.Search.Internal.UI.SearchResultsLayoutPage, Microsoft.Office.Server.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c could not be found or it is not registered as safe.

    Which is weird, since the contents of the file is still exactly the same as the ootb one. As soon as I reset to use the site definition, it works again. Any idea?

    1. OOB files can do what they want. When you customize different rules apply.

  2. first of all, i need to add a new web part zone towards the right side of the search result page, but cannot find any information on how to do so. any ideas?

    without knowing exactly what to do, i followed your instruction and created a SearchResults_custom.aspx based on SearchResults.aspx and published it (attempting to add a right web part zone). the problem i have is when i create a new result page from search center site, i don't see the new page layout available in the Page Layout select box. the only option in the select box is "(Welcome Page) Search results" which i believe is the SearchResults.aspx.

    so now i am stuck...help! thank you.

    1. Take a look at https://support.office.com/en-us/article/About-page-layout-and-site-template-settings-1acbb881-269b-4e1b-86cc-8644bfffe40b#bm2 Once you create a publishing layout and publish it, it should be available. Create a page, and you can change the layout afterwards as well - take a look at http://www.learningsharepoint.com/2013/03/07/change-layout-of-an-existing-page-in-sharepoint-2013/

    2. thanks for your prompt reply Mikael...though i am still stuck...
      i read the 2 links you suggested. what i am unclear is first of all, i noticed SearchResults.aspx is defined with content type of Master Page, but it is acting as a Page Layout. With my customized version, given it still has the content type of Master Page, is it the reason why i still cannot see it from the Page Layout selection box? which content type should it be? Master Page or Page Layout?
      in addition, i do not have the option of Page Layout in the ribbon from my search results page. i ensure the sharepoint publishing feature is activated. am i still missing something?


    3. You can make the page layout be associated with the content type "welcome page". And once in edit mode of a publishing page, you should have the "page layout" as an option under "page actions" in the ribbon.

  3. Resetting the SearchResults.aspx page to Site Definition in page layouts of site collection fixed the issue.

  4. Replacing the <%@ Page element at the top with this helps:
    <%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>