Sunday, May 13, 2007

Customize the Display of Quick Launch

http://msdn2.microsoft.com/en-us/library/ms466994.aspx

Customize the Display of Quick Launch

You can modify the display of Quick Launch by modifying attributes of the navigation control specified in the default.master file of the deployment (Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL). The default.master file is the Windows SharePoint Services master page that contains templates for site page layout, including the template for the left navigational area used in SharePoint pages.

The master page includes templates for two controls that by default are available for implementation on the Home page, a Microsoft.SharePoint.WebControls.Menu control, which displays the standard Quick Launch view used in the left navigational area, and a Microsoft.SharePoint.WebControls.SPTreeView control, which displays a site folder view. You can select which view to display on site pages through the user interface.

To select which left navigational control to display on site pages

  1. Click Site Actions and on the Site Settings page in the Look and Feel section, click Tree view.

  2. Select Enable Quick Launch to display the Quick Launch view, or select Enable Tree View to display a folder view.

    As an example of a customization that you can make to left navigation, you can collapse Quick Launch and add fly-out menus to the view by setting attributes on the Menu control. This kind of customization requires that you either customize the originally installed default.master file through a SharePoint-compatible editing application such as Microsoft Office SharePoint Designer 2007, or that you create a custom .master file and use the Windows SharePoint Services object model to point a site to the new file.

To use SharePoint Designer to modify the default.master file instance in the site's Master Page Gallery to display a collapsed view with fly-out menus

  1. Click Site Actions, click Site Settings, and then in the Galleries section of the Site Settings page, click Master pages.

  2. On the Master Page Gallery page, click Edit in Microsoft Office SharePoint Designer on the drop-down menu.

  3. In Code view, find the ContentPlaceHolder container control whose ID is PlaceHolderLeftNavBar. Within the PlaceHolderLeftNavBar control, find the AspMenu control whose ID is QuickLaunchMenu.

  4. Set both the StaticDisplayLevels and MaximumDynamicDisplayLevels values of the Menu control to 1, as follows:

     id="QuickLaunchMenu"
    DataSourceId="QuickLaunchSiteMap"
    runat="server"
    Orientation="Vertical"
    StaticDisplayLevels="1"
    ItemWrap="true"
    MaximumDynamicDisplayLevels="1"
    StaticSubMenuIndent="0"
    SkipLinkText=""
    >
  5. Save the file and open a site page to see the results of your changes.

To display a collapsed view with fly-out menus by creating a custom .master file and using the SharePoint object model

  1. Copy the default.master file in the \12\TEMPLATE\GLOBAL folder and rename it, for example, myDefault.master.

  2. Open your new myDefault.master file and find the ContentPlaceHolder container control whose ID is PlaceHolderLeftNavBar.

  3. In the PlaceHolderLeftNavBar control, find the AspMenu control whose ID is QuickLaunchMenu, and then set both the StaticDisplayLevels and MaximumDynamicDisplayLevels values to 1, as follows:

     id="QuickLaunchMenu"
    DataSourceId="QuickLaunchSiteMap"
    runat="server"
    Orientation="Vertical"
    StaticDisplayLevels="1"
    ItemWrap="true"
    MaximumDynamicDisplayLevels="1"
    StaticSubMenuIndent="0"
    SkipLinkText=""
    >
  4. Create a Web site in Microsoft Visual Studio and use the Microsoft.SharePoint.SPWeb.MasterUrl property to point the site to the custom .master file, as shown in the following example.

    C#
    SPWeb subSite = SPControl.GetContextWeb(Context);
    subSite.MasterUrl = "/Site/SubSite/_catalogs/masterpage/myDefault.master";

    To run this example, you must add a Microsoft.SharePoint.WebControls.FormDigest control to the page making the post. For information about how to add a FormDigest control, see Security Validation and Making Posts to Update Data. The example also requires referencing and importing the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces. For basic information about how to create a Web application that runs in the context of Windows SharePoint Services, see How to: Create a Web Application in a SharePoint Web Site.

  5. Reset IIS for your changes to take effect and navigate to a site page to see the results of your changes.

Replacing the Menu Control with the TreeView Control

You can replace the AspMenu control with a SPTreeView control to display a familiar tree view with nodes that collapse and expand.

To replace the Menu control with the TreeView control

  1. Open the myDefault.master file you created in the previous procedure and find the ContentPlaceHolder container control whose ID is PlaceHolderLeftNavBar.

  2. In the AspMenu control, find the PlaceHolderLeftNavBar control whose ID is QuickLaunchMenu, and replace SharePoint:AspMenu with SharePoint:SPTreeView in both the opening and closing tags.

  3. Remove the following LevelMenuItemStyles element and its contents from the new SPTreeView element.








  4. Reset IIS for changes to take effect.

    The SPTreeView control provides properties that allow you to easily customize the control. For more information about Windows SharePoint Services master pages and site customization, see Master Pages.

See Also

Concepts

Custom Navigation and New User Interface Elements
Customizing Quick Launch and the Top Link Bar Through the User Interface
How to: Share the Top Link Bar Between Sites
Adding Links through the Object Model
Using a Custom Data Source for Navigation

No comments: