Master Pages in Community Server

I have been working on small Community Server project and learning a bit about the way they do things.  The problem I needed to solve a couple days ago dealt with the requirement that some content show up on all pages in the system.  This seems like a no brainer - just add some content to Master.ascx in the current theme and be done with it.  The issue is the definition of all.  If I add content to the main master page, it will show up on every single page including pages like login and logout.  This was not the intent of the requirement even though it was the wording of the requirement.  So I needed to add this content to the all* pages.  Where the * implies the content doesn't show up on pages where it does not make sense.  Faced with the option of adding the content to individual pages or individual master pages, which would be a maintenance pain, I came up with the following solution.

  1. Add a new CS:MPSection to Master.ascx; give it the id "rcrcommon".
  2. Create a new master page - call it RightContentMaster.ascx.  RightContentMaster has the shared content on it and uses Master.ascx as its master page.  The shared content is in a CS:MPContent control with the id "rcrcommon".  I changed HomeMaster, BlogMaster, ForumMaster, etc. to use RightContentMaster as their ThemeMasterFile.

This allowed pages that rely solely on Master.ascx for layout to continue to function and display as they always have, but added my new content to the rest of the pages in the system.  The reason this works is the inheritance of the master pages that CS has provided and the way I was able to insert my new master page into that rendering pipeline so only the pages I need get the content, but it is on 90% of the pages in the site.

I decided I needed to know more about how the master pages in CS work and how I can work with them.  I started by reading Jeff's overview post on this topic to get a baseline for what is going on with the system:

The most common base implementation of a master page is of 3 sections called 'lcr' (left side content), 'bcr' (body content, and 'rcr' (right side content). You can either define controls for every descendent page in these sections in the master page, or override master page content by declaring CS:MPContent controls with these ids on your aspx page. Skins should not implement these content controls. For example, if you wanted to understand how each thing is showing up on default.aspx, you would open default.aspx and find the 'ThemeMasterFile' attribute on the page level CS:MPContainer control. If you navigate to the HomeMaster.ascx file you'll see that the only thing being added here are some style includes in a "HeaderRegion", and the 3 content sections.

Jeff tells us that a page using a master file has two important things it can do.

  1. "define controls for every descendent page in these sections in the master page"
  2. "override master page content by declaring CS:MPContent controls with [the same] ids on your aspx page"


Looking at Master.ascx in CS, we find a page with the following layout:

The regions highlighted in blue are the ones most often changed, but there are a bunch of things that can be done with this layout including changing headers and footers and even adding content outside of the page form.

Armed with this knowledge, I made the changes outlined above.  An updated diagram of Master.ascx looks like this:

My RightContentMaster page overrides the rcrcommon content area to add my content to most of the pages.  Here are the advantages of this method as I see them:

  1. I can control the pages where this content is shown by switching between RightContentMaster.ascx and Master.ascx as the base ThemeMasterFile.
  2. I only have one place to edit this content (RightContentMaster.ascx).
  3. If I ever need to change the content on a page I should be able to override the rcrcommon section with a new one.

The main disadvantage that I see is the need to change other master pages to use RightContentMaster.  If anyone has any thoughts on this way of doing things, I would love to hear them.

Comments

No Comments

Leave a Comment

(required )  
(optional )
(required )  

Enter the numbers above:
Add Comment