Monday, March 14, 2011

Add global navigation to SharePoint 2010 Search Center

-- 11/29/2011 UPDATE --
Thanks to Falk and Furiant for the comments and troubleshooting. I've added an extra step to account for situations where users have read-only permissions. The corev4.css style sheet does not get loaded by default on minimal.master for these users and therefore does not style the navigation properly.

John Ross from SharePoint 911 has an article that describes why SP2010 search center templates use minimal.master for their master pages.

http://www.sharepoint911.com/blogs/john/archive/2010/05/12/sharepoint-search-center-uses-minimal-master-%E2%80%93-and-why-you-should-care-about-that.aspx

One of the most frequent requests I get from users that have (fairly) vanilla SP2010 deployments is to have the global navigation links included on search pages. The simplest way to do this is to make a copy of minimal.master and copy a div tag from v4.master. Here are the steps:

1. Open SharePoint Designer and connect to the root of the site collection where your search center lives. You’re going to need to access to the master page gallery.

2. Select “Master Pages” from the “Site Objects” pane on the left.

3. Make a copy of “minimal.master” and name it something nice like “search.master”. Open this new master page in split view.

4. Find the div tag that encloses the “PlaceHolderTitleBreadcrumb” content place holder control and paste in this markup (which I just copied out of v4.master) right above it.

<div class="s4-lp s4-toplinks">
    <asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">
        <asp:ContentPlaceHolder id="PlaceHolderHorizontalNav" runat="server">
            <SharePoint:AspMenu
                ID="TopNavigationMenuV4"
                Runat="server"
                EnableViewState="false"
                DataSourceID="topSiteMap"
                AccessKey="<%$Resources:wss,navigation_accesskey%>"
                UseSimpleRendering="true"
                UseSeparateCss="false"
                Orientation="Horizontal"
                StaticDisplayLevels="2"
                MaximumDynamicDisplayLevels="1"
                SkipLinkText=""
                CssClass="s4-tn"/>
            <SharePoint:DelegateControl runat="server"
                ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
                <Template_Controls>
                    <asp:SiteMapDataSource
                        ShowStartingNode="False"
                        SiteMapProvider="SPNavigationProvider"
                        id="topSiteMap"
                        runat="server"
                        StartingNodeUrl="sid:1002"/>
                </Template_Controls>
            </SharePoint:DelegateControl>
        </asp:ContentPlaceHolder>
    </asp:ContentPlaceHolder>
</div>

5. Find the CSS registration tag for minimalv4.css and paste in this tag right above it.

<SharePoint:CssRegistration Name="corev4.css" runat="server"/>

6. Save, check in, and publish the new master page.

7. Browse to your search center and change the site master page to use the one you just published. Your global navigation should now show up directly below the dark blue band that has the site logo and title.

19 comments:

  1. I followed your instructions above, thank you for simplifying this by the way, I am not really developer and this new to me. Ran into a snag when I went to the master page gallery to publish my newly created search.master but the Publish button is grayed out, yes the file is checked in and yes I am a site adminstrator. newbie fathead thing I am sure but any help you have time give is appreciated.
    davidh

    ReplyDelete
  2. davidh: Sorry, I made some assumptions in my instructions. When you check in with SharePoint Designer, you should select "Publish a major version". This would then prompt you to approve the version in the browser. It sounds like you did this, so the next step is to approve. There is a small button in the ribbon called "Approve/Reject". That should take care of it for you.
    -Rob

    ReplyDelete
  3. Rob, I apologize for taking your time with this kind of question. If you don't have time to deal with this I certainly understand. When I check-in the search.master in SP Designer I am not presented with a selction to "Publish a major version", I am only presented with a dialog inviting me to add comments, I click ok and it closes and the page is checked in. I know I am missing something silly I just wish the heck I knew what it was. thank you again.
    davidh

    ReplyDelete
  4. davidh: Then it's possible you don't have content approval turned on for your master page gallery. Not a big deal. You could check the library versioning settings to see if that's the case. Either way, it sounds like you're dealing with a published file, so you should be able to change the master page on the search site. If you have a less-privileged account, you can test and make sure that there aren't any problems with the visibility of the master page.

    ReplyDelete
  5. You are correct, when I checked I did not have content approval turned on. I tried to change the master page on the search site by using this url that I found on a technet forum /_layouts/changesitemasterpage.aspx
    but I get an error box with that and I can't find a place in the site settings to actually change the master page. I have administrator rights to the site collection and the farm for that matter. I really do appreciate your help and have already learned several things from your blogs.

    ReplyDelete
  6. davidh: You can't change the master page from the web UI without having publishing features enabled. There are features at both the site collection and site levels. You may need to activate both depending on how your environment is setup. Once the feature is enabled on the search site though, you should be able to change the master page from the "Look and Feel" section of Site Settings.

    ReplyDelete
  7. Spot on! I had activated publishing for one of the other site collections but not for this one, this one is my sandbox site collection. Once it was activated at both the site collection and at the serach site itself, BINGO, I had navagation once again. Now I can incorporate this into my production site collections just in time to get a few points in with the boss before the board of directors does their annual salary review. I owe you a beverage of your choice. Thanks again for the help and the guidance.
    davidh

    ReplyDelete
  8. Thanks for this information. But implementing this on my SharePoint test environment broke my admin page of the team site. When i go to site settings i get some kind of menu with the other team sites, but when i go to like the Themes menu it gives me an error.

    What did i do wrong?

    ReplyDelete
  9. Bram: It sounds like you may have changed the system master page. This could cause the problem you're describing. Please make sure you're only setting the site master page to the new search.master.
    -Rob

    ReplyDelete
  10. Rob, i will check this, thanks for you help. I think i overlooked that option, i'm a starter with SharePoint so still try things and find me doing something wrong. Well thats the learning process i guess :-)

    ReplyDelete
  11. Thanks for this article. After adding the code and publishing/approving, I'm seeing the navigation. But I only see it correctly when I'm logged in with administrator rights to the search center. When I log in as a normal user, I get an unstyled bulleted list for navigation.

    ReplyDelete
  12. Hi
    I got the ame problem as Furiant got.
    Navigation isn't showing right as normal user.
    the user must has contribute right in order to see the right navigation but this is no opportunity

    regards Falk

    ReplyDelete
  13. Furiant and Falk: Sounds like your issues are related to stylesheets. My solution assumes you are using the standard corev4.css. If you are applying your own branding, you may need to style the nav yourself.

    ReplyDelete
  14. Hey
    I am using a custom CSS (defined in the ChangeSiteMasterPage.aspx) but even when i Use Microsoft SharePoint Foundation default styles
    the menu isn't showing right.
    I don't know what the problem is.
    Do you have some more tips?

    regards Falk

    ReplyDelete
  15. Hi again I evaluated that users need the folowing permission to see the menu normal

    Edit Items - Edit items in lists, edit documents in document libraries, and customize Web Part Pages in document libraries.

    But why
    regards Falk

    ReplyDelete
  16. Falk: Thanks for the detail. I've figured out what the problem is. The minimal master page that the search center uses by default loads the minimalv4.css style sheet, not corev4.css, and for some reason elevated privileges cause corev4 to be loaded, maybe due to ribbon requirements. The ribbon is not visible in the search center for read-only users. I'll update my post to include the necessary step. It's just adding another line to the new master page.

    ReplyDelete
  17. Hey Rob
    thank you for the update, you are the first i could find who solved this problem.

    ReplyDelete
  18. Rob, I was never able to get this to work, even after changing style sheets. The css never looked quite right. But I appreciate you taking the time help the community.

    I was able to get it working with the minimalv4.css and the code found on
    http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/thread/cd568f4b-6372-480a-b393-ad3d9ab1db84

    Thanks,
    Craig

    ReplyDelete