Thursday, March 11, 2010

Page Layout with Show Hide Title option

I think this is another common request from client. They need limited page layout but they need each layout to be very flexible. And one of them is that they should be able to decide to Show/Hide Title of the page.

Workaround can be to create 2 page layouts but thats lot to maintain for them.

title optional

Solution ( Approach 1 ):
Let me explain you the approach first.

1. Added a column/field to the Page Content Type - ShowTitle of the type Boolean

2. Added a column/field to the Page Content Type - TitleOnPage of the type Calculated Column with Formula :

3. Here's the Markup adjusted to handle the Show/Hide of Title

<asp:Content contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">

<WebPartPages:WebPartZone runat="server" Title="loc:TitleBar" ID="TitleBar" AllowLayoutChange="false" AllowPersonalization="false"/>

<span><SharePointWebControls:ListItemProperty ID="ListItemProperty2" Property="TitleOnPage" MaxLength=40 runat="server"/></span>
<span> <PublishingWebControls:EditModePanel runat=server id="EditModePanelB">

<SharePointWebControls:TextField runat="server" id="TitleField" FieldName="Title"/>
<SharePointWebControls:BooleanField FieldName="ShowTitle" runat="server" id="BooleanField1" />


Solution ( Approach 2 ):