Tuesday, January 25, 2011

How to: Frame a search center with little work

Lately I have encountered several customs who deploy search from SharePoint 2010, but they still have other solutions running on MOSS 2007 or other portal frameworks. Instead of creating custom solutions using the search service on SharePoint 2010, framing is a quick solution to get you up and running.
One way is to create a custom master page to replace v4.master for the search center, but this requires html knowledge and tinkering. In many cases it’s just as easy to go the configuration way.

Hello IsDlg=1and s4-notdlg

You have probably seen throughout SharePoint 2010 that it opens modal dialogs for different tasks. For example if you want to create a new site you get a dialog looking something like this
image

The source for this page is loaded from /_layouts/AddGallery.aspx?IsDlg=1

The part to note is the appending of IsDlg=1 which tells the page it is rendered in a modal dialog. In effect this will change some styles for the page which hides the ribbon and top menus based on the style sheet class s4-notdlg. (MSDN: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.unsecuredlayoutspagebase.isdialogmode.aspx).

In order for a page to frame in search they will merely append IsDlg=1 to the search center url.

image

Unfortunately the IsDlg=1 parameter is not added automatically to all links. There are a couple of places we need to edit.

First off is the  Advanced link. Edit the search page and append IsDlg=1& to the link

image

After saving switch over to the People search box and do the same edit for the people search result page.
In theory we could add ?IsDlg=1 to the result page link as well, but this won’t work as ?k=searchterm is added in front of it, and two question marks in the url messes up the parsing.
Instead we modify the xslt for the result pages by a small style sheet entry.
<xsl:text disable-output-escaping="yes"> 
<![CDATA[
<style type="text/css">
.s4-notdlg { display: none !important }
</style>
]]>
</xsl:text>    
This can be places below <xsl:template match="/">  at the end of the default xslt. Do the same for the xslt on the people search result page.

The caveat with setting the s4-notdlg style is that it will hide the ribbon menus regardless of the IsDlg query parameter. This leads us to have one search center for framing and one which is used natively in SharePoint 2010.

So the question remains, is it better to rely on IsDlg and s4-notdlg or should I go for a custom master page?

[Also postet at http://nuggets.comperio.no]