in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Michael Hofer - SharePoint Blog

Michael Hofer's blog about adventures in SharePoint land, including tips and tricks for all products and technologies used in Information Worker solutions.

Building professional internet sites using MOSS 2007 - Page Titles (Part 3)

This post is how to build composite page titles using an enhanced FieldValue WebControl.

Page Titles are very important for internet sites since more and more search engines rank pages higher that contain (parts of) the search phrase in the page title. That's why it makes sense to show keywords of your site in your page title - together with the actual location and maybe even the company name. This is what I would call a "composite page title".

Example? See http://www.schleuniger.com/DesktopDefault.aspx/tabid-44/74_read-1590/ from site which I've built some years ago (yes, I know it was not built using MOSS, but the business case is the same).

<title>PowerStrip 9500 BF Automatic wire cutting and stripping machine, cut, strip, wire stripping, coaxial cable stripping, automatic</title> 

The title is built using the following pattern: <current location> <product related keywords (same for all products). If you check the other pages you'll find out that not all pages have these composite page titles - it is up to the editor to add them or not, but the <current location> part is of course always present.

I was thinking about how to realize this with MOSS. It is basically a very easy scenario, just add some "FieldValue" web controls in your page layout and that's it. However, I want things to be more "scalable". I want to be able to build composite page titles that do have separators, thus a "suffiix" or a "prefix". I even want to be able to provide a default if one part of the page title pattern does not contain a value (to add some default keywords or whatever). Now this is a little (tiny) bit more complicated.

Creating the control 

I've created a new WebControl that inherits from BaseFieldControl:

using System;
using Microsoft.SharePoint.WebControls;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint.Security;
using System.ComponentModel;

namespace MichaelHofer.SharePoint.PublishingEnhancements
{
    [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
    SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true),
    AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class EnhancedFieldValue : BaseFieldControl
    {
        public EnhancedFieldValue()
        {
            base.DisableInputFieldLabel = true;
            base.ControlMode = SPControlMode.Display;
        }

Now I've added the properties I want to be able to configure when I use the control in my page layout or master page:

       protected string m_Prefix = default(string);
        [Bindable(true), Category("Data"), DefaultValue(""), Description("Prefix applied before the field's value.")]
        public string Prefix
        {
            get { return m_Prefix; }
            set { m_Prefix = value; }
        }

        protected string m_Suffix = default(string);
        [Bindable(true), Category("Data"), DefaultValue(""), Description("Suffix applied after field's value.")]
        public string Suffix
        {
            get { return m_Suffix; }
            set { m_Suffix = value; }
        }

        protected string m_Default = default(string);
        //[Bindable(true), Category("Data"), DefaultValue(""), Description("Default applied if field value is empty.")]
        public string Default
        {
            get { return m_Default; }
            set { m_Default = value; }
        }

At last, I implement my own RednerFieldForDisplay-method:

        [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
        protected override void RenderFieldForDisplay(HtmlTextWriter output)
        {
            string fieldValue = base.Field.GetFieldValueAsHtml(this.ItemFieldValue);
            if (string.IsNullOrEmpty(fieldValue) && !string.IsNullOrEmpty(m_Default))
                fieldValue = m_Default;
            if (!string.IsNullOrEmpty(fieldValue))
                output.Write(string.Format("{0}{1}{2}", m_Prefix, fieldValue, m_Suffix));
        }

If there is no value given for the Field, the default will be applied. If even then there is nothing to write, prefix and suffix are not rendered, otherwise, if present, the value is rendered with the corresponding pre- and/or suffix.

Deyploment: 

I won't go into the details of deploment in this post, everything is described in detail in my former post Part 2 (see below) 

Creating composite page titles

In your page layout/master page editor (in my case SharePoint Designer), make sure that you have a reference to the assembly containing the EnhancedFieldValue control (see also my last post details). For some reason, SPD doesn't list the control in the "Web Controls (Sharepoint)" section. However, when you start typing the Prefix of the Assembly, it will show you the present controls. Now go ahead and create your composite page title. Example:

<%@ Register Tagprefix="PublishingEnhancements" Namespace="MichaelHofer.SharePoint.PublishingEnhancements" Assembly="MichaelHofer.SharePoint.PublishingEnhancements, Version=1.1.0.0, Culture=neutral, PublicKeyToken=7ce575c89ea427a4" %> 

<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
 <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
 <PublishingEnhancements:EnhancedFieldValue runat="server" id="pageTitleExtensions" FieldName="Title_x0020_Extension" Prefix=" - " Suffix=" - Copyright 2007, Michael Hofer" Default="MOSS, WSS, SharePoint, Office" />
</asp:Content>

I'm using a custom field "Title Extension" which an editor can fill within the "Edit Mode Panel" for each field. If the field is blank or for some reason not present, the default is rendered, together with the specified pre- and suffix. The page title is then (no value given) rendered as:

Enhanced Page Titles - MOSS, WSS, SharePoint, Office - Copyright 2007, Michael Hofer

I think that justifies the small development that can be easily deployed using a clean and managable SharePoint Solution!

The next thing I will look at a little bit closer is how to easily (and easy to maintain!) landing pages for a MOSS site. What I mean is:

www.myinternetsite.com/products will redirect to www.myinternetsite.com/products/pages/default.aspx
www.myinternetsite.com/newsletter will redirect to www.myinternetsite.com/signup/default.aspx etc.

Please read also Part 1 & Part 2 of this series who are about building dynamic MetaTags.

Comments

 

Frank Daske said:

Hi Michael, only to be complete at this point: The website www.schleuniger.com was created with the 100% Microsoft ASP.NET based Business  Content Management System contentXXL. The CMS has special features for global acting companies like advanced multi-language / multi-site handling and an included category system, that makes ist easy to display related content automatically. There is a SharePoint Connector available, so content can be edited in Sharepoint/WSS and published easy and cost-effective to the public web.

October 30, 2007 5:52 AM
 

Jaimes said:

Hi Michael,

I have created a page layout with multiple sort nav (tabs) on the page itself. It works now and there is no problem when using the IE browser. Now here comes the issue, when I accessed the page using firefox, the last tab doesn't show the Return to link to the first tab. Comparing it to the IE, the tabs that only appear are those with text content in it. In firefox, there are other tabs that appear and when you look at the last empty tab, I found out that there exists the Return to link.

What can I add so that when the page is accessed in firefox, only the tabs with content will appear? If that is not possible, how can I then put the Return to link to the last tab with content?

February 7, 2008 1:01 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About mhofer1976

For all of my IT carreer, I've been addicted to Microsoft-based software development, starting with VB, but then heading straight towards the .NET Framework in its earliest days. While working in different positions as a lead developer, project manager, pre-sales consultant and most recently a business unit manager, I've always kept beeing a developer and specialized on solutions in the Information Worker area, with an emphasis towards Enterprise Content Management. The Microsoft Office System and especially the SharePoint products and technologies are my favorite "playground", one big reason why I've joined the Microsoft Consulting Services in Switzerland where I'm currently working as Senior Consultant for Information Worker solutions.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts