|
||
Open the web project in Visual Studio, right-click the CMSTemplates folder in the Solution Explorer window and create a new sub-folder named MySite. Please note that the folder name must be the same as the code name of your site to ensure that the contents are exported/imported along with the website if it is deployed to another location.
Right-click the MySite folder, select Add new item... and create a new Master page called MyMaster.master. If you are a VB developer, you may want to choose Visual Basic in the Language drop-down list.
Replace all default ASPX code from the master page (in the Source view) except for the first line with the <%@ Master %> directive with the following code:
<%=DocType%> |
The CMSPortalManager control ensures the loading and saving of content between the database and editable regions. It also provides the management necessary for web part or widget zones defined on child ASPX pages.
Add the ToolkitScriptManager control after the CMSPortalManager control to allow AJAX components to work on the pages of your site:
<ajaxToolkit:ToolkitScriptManager ID="manScript" runat="server" EnableViewState="false" /> |
Switch to code behind and add a reference to the CMS.UIControls namespace:
[C#]
using CMS.UIControls; |
[VB.NET]
Imports CMS.UIControls |
Change the class definition so that the master page inherits from the TemplateMasterPage class:
[C#]
public partial class CMSTemplates_MySite_MyMaster : TemplateMasterPage |
[VB.NET]
Partial Class CMSTemplates_MySite_MyMaster Inherits TemplateMasterPage |
Add the following code after the Page_Load method:
[C#]
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e);
this.ltlTags.Text = this.HeaderTags; } |
[VB.NET]
Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs) MyBase.OnPreRender(e)
Me.ltlTags.Text = Me.HeaderTags End Sub |
Now switch back to the Source mode (HTML mode) and copy and paste the HTML code from inside the <body>...</body> tags of the sample home.htm file) onto the master page after the <cms:PortalManager> control.
However, we only need the logo, main menu and footer, so replace the entire code in the <!-- main content --> ... <!-- /main content --> section with the following control:
<asp:ContentPlaceHolder ID="plcMain" runat="server"></asp:ContentPlaceHolder> |
This is a standard ASP.NET control that ensures the loading of pages into the master page.
So the final code of the <body> element of the master page will look like this:
<body class="<%=BodyClass%>" <%=BodyParameters%>> <ajaxToolkit:ToolkitScriptManager ID="manScript" runat="server" EnableViewState="false" /> |
When you switch to the Design tab, you should see a page preview like this:
Save the changes.
|
Using CSS-based layout instead of tables
If you prefer using a CSS-based layout, you can easily change the HTML code here and replace the tables with other elements (<div>, <span>, etc.). We use a table-based layout by default since it's easier to understand, although we are aware of the advantages of a CSS-based layout. |