Custom SharePoint search site template

by ZebSadiq 7. December 2010 19:55

On nearly all of the SharePoint implementations I've participated on, there has been a requirement to customise the look and feel of the search results page. This makes sense because it would be odd from the user experience for the SharePoint look and feel to change all a sudden when the user decides to search for a keyword.
Here I will try to explain how to create a custom search site template that uses one custom search results layout for all different types of search results.

Of course, for some project, a custom theme should be enough to alter the display of the search site but if you do not have a theme in place, its hard to justify creating a SharePoint theme just for the search site.

This method is only an option if you’re able to create custom site definitions and custom layouts for the site you’re trying to build.

Lets get started. First we’re going to copy the out of the box site definition for a search site and insert it into our custom ONET.xml. If you are unfamiliar with ONET.xml file/s, you should do reading on this first. This Microsoft article might be a good starting point.

Browse to the SiteTemplates folder (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates).

Inside the SiteTemplates folder, there is a folder named SRCHCEN. This folder contains the out of the box site definition for the search center site.  What we need to do is to customise and integrate a copy of it into own site definition. 
First, copy all of the resources inside this folder apart from the ONET.xml into your custom site definition folder (I’ll refer to this as ‘MyProject’ folder from here onwards). These resources are required by some parts of the search definition that we won’t be changing.

You should now have a search template folder that resembles something like:
\12\TEMPLATE\SiteTemplates\MyProject >
Lists (Folder) > Tabs (Folder) > Set of files
XML (Folder) > ONET.xml (not copied from the SRCHCEN folder)

Next we will edit our custom ONET.xml and insert bits from the SRCHCEN > XML > ONET.xml file. Open both files in a text editor.

In the SRCHCEN ONET.xml file, locate the following tag (on Line 78):

<Configuration ID="0" Name="Default">

We need to copy all contents of the <Configuration ID="0" Name="Default"> and its closing tag </Configuration> (on Line 157). We then need to paste this into the MyProjects version of ONET.xml inside the <Configurations> tag.

You will have to make sure that the inserted configuration’s ID tag is changed to something unique in relation to other configurations contained inside your ONET.xml.

<Configuration ID="2" Name="Default">.

Next you will need to go back to the SRCHCEN ONET.xml file and locate the following tag (on Line 163):

<Module Name="PageUpload" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">

Again you need to copy all contents from this module tag into the <Modules> tag inside the MyProject ONET.xml file.

Next you will need to replicate the out of the box search results layout page.  You can find this in the PortalLayouts feature (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\PortalLayouts). The file is called searchresults.aspx. Once you create a copy of this file, makesure you give it a unique name like MyProjectsearchresults.aspx . I’ll assume here you know how to add a custom layout to SharePoint. If not, please read this article.

Once the MyProjectsearchresults.aspx is in place, go back to the MyProject ONET.xml file. Inside the <Module Name="PageUpload" Url="$Resources:cmscore,List_Pages_UrlName;" Path=""> you copied earlier, for each <File> tag, find it’s PublishingPageLayout property:

<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/...â" />
and change the file name to your own search results layout file  e.g.
<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyProjectsearchresults.aspx, $Resources:spscore,SearchCenterAdvancedSearchTitle;" />

You should do this for all <File> tags so that all search results page inside the template use your custom search results layout.  You can also modify other properties of each <File> tag to get exactly what you need on your search result pages (e.g. What web parts need to be added to the search pages when an instance of your search site is created).

The last step is to go back to the search configuration tag inside <configurations>. Locate the feature:
 <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416"> inside the <WebFeatures> . In its AvailablePageLayouts property, change the reference to the out of the box search results layout to MyProjectsearchresults.aspx :

<Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/ masterpage/searchmain.aspx: ~SiteCollection/_catalogs/masterpage/MyProjectsearchresults.aspx: ~SiteCollection/_catalogs/masterpage/PeopleSearchResults.aspx: ~SiteCollection/_catalogs/masterpage/AdvancedSearchLayout.aspx "/>

You can remove the other layouts from this tag if you don’t want the user to create those types of pages in your search site.

If you’re deploying your MyProjectsearchresults.aspx file through a feature (which you should be doing), it would be worth adding a dependency to that feature inside the <WebFeatures> section of the search configuration tag. This will ensure that the custom layout page is added to the SharePoint gallery before the site is provisioned.

As a result, next time you create a search site using the custom configuration, the search result pages will use your custom search results layout. Everything else should work perfectly like it does out of the box.


Add comment

  Country flag

  • Comment
  • Preview


<<  February 2024  >>

View posts in large calendar