Kentico CMS comes with many built-in web parts and their appearance and design can easily be modified to fit your specific requirements. The concept of web part layouts allows you to customize the look of a web part by defining a custom HTML layout. So the web part layout is basically a custom skin for the web part.
The layout of a specific web part can be selected by configuring () it on the Design tab of CMS Desk and switching to the Layout tab. Here you can select from a list of layouts created for the current web part, or write a new layout. This list of layouts can also be managed at CMS Site Manager -> Development -> Web parts -> .. select the given web part from the tree ... -> Layout.
Example: Customizing Newsletter subscription dialog
In this example, we will customize the newsletter subscription dialog layout. The standard layout looks like this (when no user is logged on):
Go to CMS Desk -> Content and navigate to the Examples -> Web parts -> Newsletters -> Newsletter subscription page (if you're using the sample Corporate Site).
Switch to the Design tab and configure () the Newsletter subscription web part. Click the Layout tab and choose (New) from the drop-down list. Enter the following values:
• | Display name: Narrow layout |
• | Code name: NarrowLayout |
Enter the following HTML code:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_Newsletters_NewsletterSubscriptionWebPart" CodeFile="~/CMSWebParts/Newsletters/NewsletterSubscriptionWebPart.ascx.cs" %>
<%@ Register Src="~/CMSFormControls/Inputs/SecurityCode.ascx" TagName="SecurityCode" TagPrefix="cms" %>
<asp:Panel ID="pnlSubscription" runat="server" DefaultButton="btnSubmit" CssClass="Subscription"> <asp:Label runat="server" ID="lblInfo" CssClass="InfoMessage" EnableViewState="false" Visible="false" /> <asp:Label runat="server" ID="lblError" CssClass="ErrorMessage" EnableViewState="false" Visible="false" /> <div class="NewsletterSubscription"> <table cellspacing="0" cellpadding="0" border="0" class="Table"> <asp:PlaceHolder runat="server" ID="plcFirstName"> <tr> <td> <cms:LocalizedLabel ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName" EnableViewState="false" /> <br /> <asp:TextBox ID="txtFirstName" runat="server" CssClass="SubscriptionTextbox" MaxLength="200" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder runat="server" ID="plcLastName"> <tr> <td> <cms:LocalizedLabel ID="lblLastName" runat="server" AssociatedControlID="txtLastName" EnableViewState="false" /> <br /> <asp:TextBox ID="txtLastName" runat="server" CssClass="SubscriptionTextbox" MaxLength="200" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder runat="server" ID="plcEmail"> <tr> <td> <cms:LocalizedLabel ID="lblEmail" runat="server" AssociatedControlID="txtEmail" EnableViewState="false" /> <br /> <asp:TextBox ID="txtEmail" runat="server" CssClass="SubscriptionTextbox" MaxLength="400" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder runat="server" ID="plcNwsList"> <tr> <td> <asp:CheckBoxList runat="server" ID="chklNewsletters" CssClass="NewsletterList" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder runat="server" ID="plcCaptcha"> <tr> <td> <cms:LocalizedLabel ID="lblCaptcha" runat="server" AssociatedControlID="scCaptcha" EnableViewState="false" /> <br /> <cms:SecurityCode ID="scCaptcha" GenerateNumberEveryTime="false" runat="server" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder ID="pnlButtonSubmit" runat="server"> <tr> <td align="right"> <cms:LocalizedButton ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" CssClass="SubscriptionButton" EnableViewState="false" /> </td> </tr> </asp:PlaceHolder> <asp:PlaceHolder ID="pnlImageSubmit" runat="server"> <tr> <td align="right"> <asp:ImageButton ID="btnImageSubmit" runat="server" OnClick="btnSubmit_Click" EnableViewState="false" /> </td> </tr> </asp:PlaceHolder> </table> </div> </asp:Panel> |
Click OK. When you look at the page now, you will see that the dialog looks like this (when no user is logged on):
|
Do not remove any controls from the layout
It's important to keep all the controls in the layout. If you need to hide some of them, you can add the Visible="False" attribute to the control, but the control must stay in the layout to allow the web part to keep working.
This issue may also cause problems when upgrading to a new Kentico CMS version - if some of the built-in web parts use a new control and you use your web part layout created in the previous version, the web part may stop working. Please be sure to test your website after an upgrade carefully if you're using web part layouts. |
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?customizing_web_part_layout.htm