MCMS, Master Pages and Nested Master Pages

Posted 25 January 2008, 16:50 | by | Perma-link

Obviously, there's no problem with using Master Pages with MCMS SP2, so there's a big win right there, however now that Visual Studio 2008 supports Nested Master Pages we're on a real roll.

We've defined a number of shared placeholders (e.g. page title, browser title, keywords, meta description, etc) that all templates should have, and most of these are metadata fields – more on this in a minute.

So first of all we build a base master page with all the basic page layout – headers, left hand navigation, footers, standard CSS classes, MCMS Console, and then build up some additional master pages to layout the pages further – for example one with one main content column and one with two main content columns.

We can then build our pages on these child master pages, but still have all the layout of the base master defined in one place.

The MCMS placeholders can obviously exist quite happily on any of these controls (page, specific master page or base master page, or indeed on a user control).

You remember that I said a lot of the shared placeholders where metadata? And clearly when the author is editing the page they need to be able to see the controls for them, but in presentation mode these controls need to render out in the page's metadata elements. So how did we go about this? Simple: Create a class that inherits from System.Web.UI.Page, and change our pages to inherit from this “BasePage” instead. Then, we can override the OnPreInit event and do the following:

if (CurrentUserIsAuthoring()) {
  Page.Master.MasterPageFile = "/MasterPages/BaseAuthoring.Master";
}
base.OnPreInit(e);

So we pick up the page's Master, and then change the Master Page file of that to our Base Authoring master page instead of the Base Presentation master page. This also allows us to completely change the display and style of the page in Authoring mode as well – something the client is quite keen on.


Part of the Series: The joys of using .Net 2.0, .Net 3.0 and .Net 3.5 with MCMS

Filed under: ASP.NET, MCMS