We have a cold fusion website that uses an include file for the header. In that header file the page title field is set. This header file is included in every page of the website. So, every page has the same title.

Without doing something real fancy, how can I have a different page title for each page but keep a common header include.

I would prefer not to use a db table to house them and have a dynamic title field. Is there a way to "re-set" the page title after the header file?

Thanks for the help.

Best Regards,
Rodney

Here is a simple cfswitch that uses a default title but easily handles custom titles for pages where you want a different title. The second snippet seems more organized. Your call how you would like to do this. The key is to pull the name of the file form the cgi variable script_name. You may want the whole variable including the path but this example uses just the page name.

<cfset strPage = listLast( cgi.script_name, "/" )>
<cfset strTitle = "Untitled">
<cfswitch expression="#strpage#">
	<cfcase value="index.cfm">
		<cfset strTitle = "Welcome to the Home page">
	</cfcase>
	<cfdefaultcase>
		<cfset strTitle = "Standard Title is here">	
	</cfdefaultcase>
</cfswitch>
<title><cfoutput>#strTitle#</cfoutput></title>

Here is a slightly different vesion that uses a structure (associative array) to hold the data.

<cfset strPage = listLast( cgi.script_name, "/" )>
<cfset strTitle = "Untitled">
<cfset struct_titles = structNew()>
<cfset struct_titles["default"]="Welcome to the basic title page">
<cfset struct_titles["index.cfm"]="Welcome to the Home page">
<cfset struct_titles["other.cfm"]="The other title">

<cfif structKeyExists( struct_titles, strPage )>
	<cfset strTitle = struct_titles[ strpage ]>
<cfelse>
	<cfset strTitle = struct_titles[ "default" ]>
</cfif>
<title><cfoutput>#strTitle#</cfoutput></title>
This article has been dead for over six months. Start a new discussion instead.