Dec 5, 2008

Page Layout

Master pages enable developers and designers to define the overall look and feel of the Publishing site with just a single file, along with some additional branding files such as CSS or images. Just as in ASP.NET 2.0 sites, SharePoint sites also leverage content pages that fill in the content placeholders defined within a master page. Publishing sites take this a bit further by introducing a type of content page called a page layou. Page layouts, when combined with the master page, define the rendering and layout of a page. When the page layout is requested, SharePoint fetches the master page referenced within the SPWeb.CustomMasterUrl property and merges the two together. Developers and designers use page layouts to host editable regions of a page, implemented with Web Parts and field controls.

Page layouts have a special relationship with content types within a Publishing site. Each page layout must be associated with exactly one content type. This content type must inherit from the

Page content type

found in the Publishing Content Types group. Content types are used in a Publishing site to define the schema and rules for a particular type of content. For example, a Press Release content type may have fields for the title and byline, the date of the release, the press release body, optionally some reference links, as well as references with short bios for other companies mentioned in the press release. In addition, it may also have a special workflow associated with it defining a special approval process for the press release.

Keep in mind that the content type only defines the schema and rules for the type of content; it does not address the presentation in any way. This is where page layouts come into play. Page layouts, when combined with a master page, define the rendering/look and feel of a requested page. In addition, developers can associate multiple page layouts with a single content type to give content owners the utmost control in selecting different rendering options for a particular page type. When a content owner initiates the process of creating a new page within a ublishing site, the first thing he or she has to do is select a content type/page layout combination.

Moreover, content owners are not restricted to the page layout that is selected at the time of page creation. At any point in the future, even after the page has been published, a content owner can edit the page and change the selected page layout. The only limitation is that the only page layouts available are those associated with the content type selected when the page was created. This is because a page’s content type cannot be switched from one content type to another after it has been created. In addition, page layouts can only be associated with exactly one content type; no page layout can be associated with more than one content type.

Page layout is the layout of the associated page, which is created using a content type. A Page layout is like a xslt to transform a xml(instance) of a content type(xsd). When I want to edit an instance, this instance is always instance of the associated content type(xsd), not instance of xslt. When create page layout in sharepoint designer, the first step is to select a content type(xsd). And give it a name and title. The page layout will be saved in master page gallary. So the page layout is a file. In class library, page layout inherit from PublishingLayoutPage, which inherit from WebPartPage. In sharepoint, Page Layout is a content type, it inherit from system page layout, which inherit from Page. You can add web part, field control, the field defined in the associated content type(xsd), also available. Below is example of page layout

<%@ Page language="C#"   
meta:progid="SharePoint.WebPartPage.Document" %>

<%@ Register Tagprefix="SharePointWebControls" 
Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" 
Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 

<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
 Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
   Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


Advance Recruit!

The question is master page come into play, when edit page layout in sharepoint , it is render in a master page.

To create instance of associated content type, first you need to enable a content type to a document library. Then select new "the associated content type", you then need to page layout. The page layout can be changed later.

There are two way to edit a page. one is view the page, and then select "Edit Page" in the site action.

Another way is to go the document library of the page, and use the ECB menu. To edit the content of the instance, we can do this in the IE, select the ECB menu, select edit properties. To change the page layout(xslt), we can select ECB menu, select edit in sharepoint designer, sharepoint designer will prompt you, that "The page cannot be edited in sharepoint designer, you can the content in the browser, or edit the corresponding page layout in the sharepoint designer. " , then select edit in browser, then select page menu, select "Page setting and schedule", then change the page layout selection. Below is sample of instance of content type

<%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,
Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> 
<%@ Reference VirtualPath="~TemplatePageUrl" %> 
<%@ Reference VirtualPath="~masterurl/custom.master" %>

Want ta sharepoint developer

It seems to me that page layout is like nested master page. It merge with master page, however, you can add web part, and user contents, and of course most importantly, the field controls generated by associated content type(xsd)

No comments:

Post a Comment