Archive for September, 2006

Creating a custom Master Page for your MOSS 2007 portals and sites

September 28th, 2006 by Tobias Zimmergren

When I first started discovering Master pages I didn’t know where to start and what would be needed in order for a basic and as minimalistic master page as possible to work.
I gathered information to be able to make myself a minimal masterpage which would be the startingpoint of my upcoming customizations and changes.
At first nothing worked, and since there’s no good list of what elements and contentplaceholders are needed for a masterpage to work it had to do with a lot of “trial-and-error” until I finally had a completely working basic master page.
With the help of google and some other sites around the web I noted which placeholders showed up on every master page.
Below you will see the code for a very very basic master page, in which you can insert your own custom html-tags and assign a css-theme later to make your customizations a reality.
With this small template, you can make all your existing static designs work as a master page if you just put a little time and effort into it.
######### Page file starts here ############
<%@ Master language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “
http://www.w3.org/TR/html4/loose.dtd“>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Register Tagprefix=”SPSWC” Namespace=”Microsoft.SharePoint.Portal.WebControls” Assembly=”Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingWebControls” Namespace=”Microsoft.SharePoint.Publishing.WebControls” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingNavigation” Namespace=”Microsoft.SharePoint.Publishing.Navigation” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register TagPrefix=”wssuc” TagName=”Welcome” src=”~/_controltemplates/Welcome.ascx” %>
<%@ Register TagPrefix=”wssuc” TagName=”DesignModeConsole” src=”~/_controltemplates/DesignModeConsole.ascx” %>
<%@ Register TagPrefix=”PublishingVariations” TagName=”VariationsLabelMenu” src=”~/_controltemplates/VariationsLabelMenu.ascx” %>
<%@ Register Tagprefix=”PublishingConsole” TagName=”Console” src=”~/_controltemplates/PublishingConsole.ascx” %>
<%@ Register TagPrefix=”PublishingSiteAction” TagName=”SiteActionMenu” src=”~/_controltemplates/PublishingActionMenu.ascx” %>
<html>
<WebPartPages:SPWebPartManager runat=”server”/>
<SharePoint:RobotsMetaTag runat=”server”/>
<head runat=”server”>
<asp:ContentPlaceHolder runat=”server” id=”head”>
<title>
<asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server” />
</title>
</asp:ContentPlaceHolder>
<Sharepoint:CssLink runat=”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderAdditionalPageHead” runat=”server” />
</head>
<body onload=”BLOCKED SCRIPT_spBodyOnLoadWrapper();”>
<form runat=”server” onsubmit=”return _spFormOnSubmitWrapper();”>
<wssuc:Welcome id=”explitLogout” runat=”server”/>
<PublishingSiteAction:SiteActionMenu runat=”server”/>
<PublishingWebControls:AuthoringContainer id=”authoringcontrols” runat=”server”>
<PublishingConsole:Console runat=”server” />
</PublishingWebControls:AuthoringContainer>
<asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server” />
<asp:Panel visible=”false” runat=”server”>
<asp:ContentPlaceHolder id=”PlaceHolderSearchArea” runat=”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderTitleBreadcrumb” runat=”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderPageTitleInTitleArea” runat=”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderLeftNavBar” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderPageImage” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderBodyLeftBorder” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderNavSpacer” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderTitleLeftBorder” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderTitleAreaSeparator” runat=”server”/>
<asp:ContentPlaceHolder ID=”PlaceHolderMiniConsole” runat=”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderCalendarNavigator” runat =”server” />
<asp:ContentPlaceHolder id=”PlaceHolderLeftActions” runat =”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderPageDescription” runat =”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderBodyAreaClass” runat =”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderTitleAreaClass” runat =”server”/>
</asp:Panel>
</form>
</body>
</html>
######### Page file ends here ############
As you can see there’s a javascript method in the body-tag called SpBodyOnLoadWrapper. This class is automatically loaded by MOSS 2007 and handles javascript calls.
SPWebPartManager is needed for functionality and events to work as desired. Also handles web part controls if I’m not mistaken.
The PlaceHolderMain placeholder is the placeholder that contains the page content and what not. Still unsure on the details about these placeholders, so bear with me will you.
The contentplaceholders within the <asp:panel>-block are nessesary to maintain full out-of-the-box functionality for pages to work with your own defined masterpage.
I hope this will guide you in the right direction as to starting with master page-customization. The possibilites are endless but time isn’t, therefore you can without any problems just copy/paste the above code and it should work wonders right away.

What are Master Pages and why would you use them?

September 27th, 2006 by Tobias Zimmergren

One concept we tend to see alot in the new version of SharePoint ( MOSS2007 ) are Master Pages.
Most of you probably already know what a master page is, but for those of you who don’t I will try to give an explanation here.
A Master Page is a file with the extension *.master which basically is a template for a coherent layout throughout your site. Basically it standardizes your webpage layout. The best thing with the master page is that if you change in the .master file, all files based on the masterpage will also change appearance. Easy as that.
You define content placeholders on your master page and fill those placeholders with other pages that uses your masterpage as a masterpage declaratively like this:
<%@ Page Language="C#" MasterPageFile="~/YourMasterFile.master" … … %>
Listed here are some of the benefits of using masterpages:
  • Defines a portion/part of a page separately and reuse it
  • Create a locked-in layout that defines editable regions
  • Can allow customization of the elements you reuse on each page
  • Binds a page to a page-template either at runtime or at declaration
  • Ability to designe a page that uses a page template with Visual Studio (or other tools)
Hopefully this contributed to an understanding on what the general concept of a masterpage is all about.
Coming soon is a post on how to implement your own masterpage in MOSS2007
Please leave a comment if this was helpful, or if I should improve something.

 

Welcome to my new blog

September 26th, 2006 by Tobias Zimmergren

This is my very first blogpost at here and it will certainly not be the last one.
Hope you enjoy my future additions.
- Tobias