Using Delegate Controls to Implement Minor Brand Variations in SharePoint 

Tags: SharePoint Development

The Problem

 

A problem that I have often seen in the SharePoint world is the common request to have a consistent brand across your entire farm, but therein it is required to have minor variations of that brand for various sites within the farm. A frequent use case for this is the banner image/logo. Maybe the main landing page for the intranet has a certain logo, but as you start drilling into the sub-sites, the logo should change (or other brand variations). Logos for different departments like IT, HR, Sales, etc. are often requested. Now, typically inside the master page would the HTML image tags for these logos be found, however, it can be extremely cumbersome to maintain multiple instances of a given master page, especially when the differences between these master pages is small. Also, you as the developer may not know when when/where these variations need to be implemented, thus you need something intuitive for end users to be able to customize the look and feel of these sites. So what other options are available to you when you need these small brand variations in your SharePoint sites?

 

The Solution

 

A good solution for this is the use of delegate controls. You can place these controls within your master page, and at design time (via activating/deactivating features), replace them with actual controls that live in the LAYOUTS directory. What will be demonstrated in this post is using a feature to toggle the banner image on the SharePoint Site. Other use cases I've seen for using delegate controls are:

 

  • Placing code on a page to do something (see my Site Creation Workflow).
  • Wrapping the top navigation with a delegate control to replace the current web's navigation with some custom navigation at design time.
  • Replacing the out of box bread crumb with a custom bread crumbing system.
  • Changing the layout on a web part page after instantiation.
  • Adding/removing meta tags on the page for search result tweaking (google, live, etc.).
  • Many more good uses…

 

Note: the example being displayed in this walkthrough is the ability to change the logo on different sites, however, it should be known that this can be done out of box through site setting. The reason for my choice of this particular example was that the logo for a given client I was working at was not sized well to fit into the out of box mechanism to change the logo (the logo was too long). Either way, this example serves to demonstrate the concept of maintaining small brand variations, which can be of any kind of sort.

 

The "How"

 

On the master page of a SharePoint site, there is a content place holder called "PlaceHolderSiteName". This place holder contains the logo and site name for all SharePoint sites. Within that place holder I removed all the contents and replaced them with a delegate control:

 

 

I actually left the SPLinkButton because I still wanted the user to be navigated to the home page when the click the banner. Also, you'll notice I removed the site name, because the image itself served to communicate that.

 

Anyways… within that content place holder is now a delegate control that you can start dumping controls (.ascx files) into at design time (via a feature demonstrated shortly).

 

In my visual studio project, I built out four features and four control templates, one for each banner image that I may want to rotate between on my SharePoint sites:

 

 

Inside the elements of each feature, I have a control element. The ID of the control element corresponds to the ID of the delegate control on the master page. Therefore, when this feature is activated, it will take in this case the CustomerBanner.ascx control and dump it into the "Banner" delegate control on the master page:

 

 

The code for the CustomerBanner.ascx control itself if trivial:

 

 

When all four features are installed and activated, and the controls are deployed into CONTROLTEMPLATES, you'll see the logos available to be toggled within site features:

 

 

When one of these features is active, the site will show the corresponding logo! Pretty neat if you ask me!

 

Phil

 
Posted by Phillip S. Wicklund on 11-Jul-08
0  Comment  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments

Name:
URL:
Email:
Comments: