Update: Joe Audette has decided to implement this in the next version of mojoPortal, due in a couple of weeks. He is updating the <portal:PageTitle control with this functionality.
I have from time to time needed to show a page's title within the content as a heading. The controls that come with mojoPortal don't really allow for this but I have come up with a handy little control that will show the Page Title on the page and allow you to choose how the text is rendered.
To get started, create two files; PageTitle.ascx and PageTitle.ascx.cs. Place both of these files in the <siteroot>\Controls\Custom directory (Note: You will have to create the "custom" directory). The code for the files is as follows:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageTitle.ascx.cs" ClassName="PageTitle.ascx" Inherits="Controls_PageTitle" %>
<asp:literal ID="litPageTitle" runat="server" />
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Web;
using mojoPortal.Web.UI;
using mojoPortal.Web.Framework;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;
public partial class Controls_PageTitle : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
PopulateControls();
}
private void PopulateControls()
{
PageSettings currentPage = CacheHelper.GetCurrentPage();
if(currentPage == null){ return; }
if(currentPage.PageTitle == "")
litPageTitle.Text = currentPage.PageName;
else
litPageTitle.Text = currentPage.PageTitle;
}
}
To use the control, place the following in your layout.master directly after <%@ Master
...
<%@ Register Src="~/Controls/custom/PageTitle.ascx" TagName="PageTitle" TagPrefix="cc1" %>
Now place the following where you want the Page Title to appear in the layout.master.
<cc1:PageTitle id="PageTitle1" runat="server" />
Come back soon to see a full description of how this all works.
I have decided not to describe the full functionality of this control as it is fairly self-explanatory and because Joe Audette has implemented this functionality into mojoPortal. You can use the <portal:PageTitle
control after the next release.
Happy mojo-ing.