Accessing Just the PageName of PageTitle

A place for discussion about skinning and design. Before posting questions here you should review the documentation about creating skins.

This thread is closed to new posts. You must sign in to post in the forums.
4/7/2009 12:38:22 PM
Gravatar
Total Posts 40

Accessing Just the PageName of PageTitle

Hey Joe/mojo dev community,

I'm working with a skin where I need to output the page's title on every page, but I don't want the site title along with it.  Referencing http://www.mojoportal.com/understandingthelayoutmasterfile.aspx, I see that the pageTitle is comprised of "SiteName - PageName", which can be overrided as necessary.  However, for the <title> tag that the browser uses, I still do want the "SiteName - PageName" to appear (for SEO purposes, mainly).  So, I'm wondering how to best access just the page name from a skin's layout.master file (I was thinking something along the lines of <portal:PageName id="PageName1" runat="server" />, but see that won't work). 

I'm fine using some JS or a C# function to trim off the site title, but I just wondered whether there might be a cleaner way using mojo's own nomenclature ...

Thank you,
Shaun

4/7/2009 12:55:21 PM
Gravatar
Total Posts 18439

Re: Accessing Just the PageName of PageTitle

Hi Shaun,

I would just create a simple UserControl, then declare the UserControl in the layout.master using Register something like this:

<%@ Register Src="~/pathtoyour.ascx" TagName="PageNameControl" TagPrefix="co" %>

Then add the control in layout.master like:

<co:PageNameControl id="pn1" runat="server" />

Then the code for a simple UserControl would be about like this (not tested):

<%@ Control Language="C#" AutoEventWireup="true" ClassName="PageNameControl.ascx" Inherits="System.Web.UI.UserControl" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>


<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
PopulateControls();
}

private void PopulateControls()
{
PageSettings currentPage = CacheHelper.GetCurrentPage();
if(currentPage == null){ return; }
lblPageName.Text = currentPage.PageName;

}

</script>

<asp:Label ID="lblPageName" runat="server" />

Hope it helps,

Joe

4/7/2009 12:59:14 PM
Gravatar
Total Posts 40

Re: Accessing Just the PageName of PageTitle

Hey Joe, thanks as always for the fast response - I didn't think off-hand of the user control approach, but see this will be the best implementation over the long-haul!

Regards,
Shaun

4/7/2009 1:06:17 PM
Gravatar
Total Posts 18439

Re: Accessing Just the PageName of PageTitle

Hey Shaun,

Thanks a lot for the beer! Today after work I will drink a few beers celebrating our inclusion in the Web App Gallery!

Cheers,

Joe 

7/26/2009 2:41:03 PM
Gravatar
Total Posts 2183

Re: Accessing Just the PageName of PageTitle

Hey Joe,

I am trying to use the PageTitle control without the SiteTitle included. I have used your "Page Title Format" page at http://www.mojoportal.com/seo-page-title-format.aspx as a reference so I have the PageTitleFormatName key in my user.config set to show TitleOnly. This works fine in the actual <title> of the pages but I am using the PageTitle control in the content of my pages and it shows the SiteTitle - PageTitle format. Is the PageTitle control not controlled by the PageTitleFormatName key?

Thanks,
Joe

7/27/2009 5:51:53 AM
Gravatar
Total Posts 18439

Re: Accessing Just the PageName of PageTitle

Hi Joe,

PageTitle is a legacy control not used in any current skins as far as I know. I recomend remove it from your layout.master and then it should follow your config settings.

Hope it helps,

Joe 

7/27/2009 1:15:35 PM
Gravatar
Total Posts 2183

Re: Accessing Just the PageName of PageTitle

I am not using the PageTitle control for the actual <title> of the page. I am using it to display the title of the page in the content of the page. Is there a control I can use that will display the page name in the content?

7/28/2009 7:28:41 AM
Gravatar
Total Posts 18439

Re: Accessing Just the PageName of PageTitle

Hi Joe,

The PageTitle control is for setting the page <title> it is a legacy control no longer used in our skins, a relic from the .NET 1.1 days.

My first response on this thread showed how to make a UserControl that could display a page name. I can easily create a PageName control so it is available built in in the next release. It would take me all of 5 minutes to make one.

Best,

Joe

7/28/2009 9:57:28 AM
Gravatar
Total Posts 2183

Re: Accessing Just the PageName of PageTitle

Joe - Sorry for being such a dunce. I read your post about creating a user control and immediately thought, no that's not what I want. I should have given it more thought. I used the code you suggested and modified it a bit and it works great!

At first I used it just as you suggested and it worked fine except that it displayed the actual PageName ignoring the PageTitle override if present. So I modified the code to use the PageName only if the PageTitle Override was blank. Here's the modified section of code:

if(currentPage == null){ return; }
if(currentPage.PageTitle == "")
lblPageName.Text = currentPage.PageName;
else
lblPageName.Text = currentPage.PageTitle;

This brings me to some praise for you. Thank you so very much for the SourceCode Documentation. I have used a lot of OpenSource products and a lot of them don't have Source documentation at all. Instead of having to tredge through the code to find what I needed, I did a simple search in Docs and I was home free!

Awesome!

-Joe D.

You must sign in to post in the forums. This thread is closed to new posts.