Sitefinity CMS

Creating and Importing Master Pages Send comments on this topic.
See Also
Designing with Sitefinity > Master Pages > Creating and Importing Master Pages

Glossary Item Box

Sitefinity uses ASP.NET master pages as the basis for its page templates. Templates define the layout of pages within Sitefinity. Each page you create is assigned a particular template. If you change the structure of a master page, all pages defined by that master page, as well as by its template, will change.

 

Creating a New Master Page in Visual Studio

  1. Launch Visual Studio 2005.
  2. Select App_Master, right-click and choose Add New Item.
  3. Select Master Page template,
  4. Change name to desired value.
  5. Click Add.

      Create Master Page in Sitefinity Project

     Figure 1

 

In order to view it in the Admin part of Sitefinity, the IIS must be reset. To do that, choose Start -> Run -> iisreset . Then, refresh the Sitefinity application. The master page will already appear in the All Templates list of the Templates section in Sitefinity Admin (in this example, the new master page is called Try_MasterPage.master):

 

All Templates in Sitefinity Admin

 Figure 2

 

Enter the following code in order to test the master page:

Try_MasterPage.master Copy Code
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Try_MasterPage.master.cs" Inherits="App_Master_Try_MasterPage" %>
<
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<
head runat="server">
   
<title>Untitled Page</title>
</
head>
<
body>
   
<form id="form1" runat="server">
   
<div id="header" style="clear: both; height: 60px;">
       
<h1>Telerik</h1>
       
<asp:contentplaceholder id="TopMenu" runat="server"/>
   
</div>
   
<div id="MainBody">
       
<asp:contentplaceholder id="UpperBody" runat="server"/>
       
<hr />
       
<asp:contentplaceholder id="LowerBody" runat="server"/>
   
</div>
   
<div id="Footer">2007 © Telerik. All rights reserved </div>
   
</form>
</
body>
</
html>

 

The content placeholder tags should either be closed by a tag "/>" or the tag "</asp:contentplaceholder>" should be placed at the same line as the opening tag. This should be done in order to enable the drag-and-drop operation while in page edit mode in the admin part. Otherwise, if placed on the following line, Sitefinity assumes there is already a content in there.  

 

The result should be the following content of the new master page:

Master Page Content

 Figure 3

 

Have in mind that if a master page is created in the App_Master folder, it will automatically be added and be available in the Admin part of Sitefinity after the application is restarted. There is no need to upload that master page using the Sitefinity interface (the Admin part). If the latter is done, a second version of the master page will be created. 

 

Uploading an Existing Master Page to a Sitefinity project

  1. Launch Visual Studio 2005.
  2. Select the Files folder in the project, right-click and choose Add Existing Item. 
  3. Add the existing master page. 
  4. Go to Sitefinity Admin, Pages tab, Templates section.
  5. Click Upload Master Page. (See Figure 4)
  6. Select the Files folder and then choose the master page you have saved. 

     Uploading a Master Page

     Figure 4

     

The file which is to be uploaded must be with extension .master.

 

 

Using Master Pages in the Admin Part

When a page is in Edit Mode there are Select boxes in the upper part of the Admin which provides options for selection of master pages and templates.  Choose from the drop-down list the desired master page: Set Master Template in a Page

Figure 5

 

The final result will be visible after choosing the master template. Sitefinity will create a new page based on that template. (See Figure 6) Master Page Result

 Figure 6

 

See Also