SharePoint 2013 WCM Advanced Cookbook
上QQ阅读APP看书,第一时间看更新

Hiding unwanted master page controls

By default, SharePoint has a large number of SharePoint-specific controls and content zones added to each master page. SharePoint requires most of these controls in order to work correctly. When removing an undesirable control from the master page, we generally hide the control rather than removing it completely. This ensures SharePoint has access to the control, but does not render it to the end user.

Many of the controls included on the SharePoint master pages are required for the page to render correctly. When removing a control we can test whether it can be removed completely. If the page generates errors about the missing control, we know we need to hide it instead of removing it completely.

In this recipe, we will hide the suite bar branding (SharePoint or Office 365) and suite bar links (Newsfeed, SkyDrive, and Sites) using our customized master page.

Hiding unwanted master page controls

How to do it...

Follow these steps to hide unwanted master page controls:

  1. Open SharePoint Designer.
  2. Select Open Site. Enter the complete URL to the SharePoint site and select Open.
  3. From the Navigation pane, select Master Pages.
  4. In the list of files in the Master Pages library, make a copy of seattle.master (in our example, we have renamed it Seattle_HideControls.master).

    When modifying master pages included with SharePoint, do not modify the included master page. Make a copy of the master page and make your changes to the copy and then check out the new Seattle_HideControls.master master page.

  5. Open the Seattle_HideControls.master master page.
  6. Locate the </SharePoint:SharePointForm> closing tag for the SharePointForm element as shown in the following screenshot:
    How to do it...

    Tip

    The <SharePoint:SharePointForm> tag results in the <form> tag when rendered in the browser. It is important to ensure our SharePoint controls remain inside the <SharePoint:SharePointForm> tag to prevent errors on the page.

  7. Add a <div> container to hide our controls before the </SharePoint:SharePointForm> element as shown in the following code:
    <div style="display: none;">
    </div>

    The following screenshot shows these elements:

    How to do it...
  8. Locate the <div id="suiteBarLeft"> element.
    How to do it...
  9. Cut the contents of the <div id="suiteBarLeft"> element to remove them from this location and allow us to paste them later. The following screenshot shows this <div> element:
    How to do it...
  10. Paste the following contents into the <div> tag that we created earlier to hide the elements:
    <div style="display: none;">
    <SharePoint:DelegateControl id="ID_SuiteBarBrandingDelegate" ControlId="SuiteBarBrandingDelegate" runat="server"/>
    
    <SharePoint:AjaxDelta runat="server" id="DeltaSuiteLinks" BlockElement="true" CssClass="ms-core-deltaSuiteLinks">
        <div id="suiteLinksBox">
            <SharePoint:DelegateControl id="ID_SuiteLinksDelegate" ControlId="SuiteLinksDelegate" runat="server" />
        </div>
    </SharePoint:AjaxDelta>
    </div>

    We can remove the <div> elements we pasted, which surround the SharePoint controls. All we need to ensure is that the controls are on the page.

    How to do it...
  11. Save the master page.
  12. Check in and publish the master page using the Check In and Publish options.
  13. Set the master page as the Site Master Page.
  14. Navigate to the site in your preferred web browser to observe the results. You will see a screen similar to the following screenshot:
    How to do it...

How it works...

In order for SharePoint pages to render correctly, most of the server controls included on the default master pages are required. Using CSS to hide server controls allows for SharePoint to render the control while the browser hides it for the end user. Rendering the control, even though hidden, still requires server and browser resources. It will still impact the page load performance.

See also