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,

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">
		<cfset strTitle = "Standard Title is here">	

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 ]>
	<cfset strTitle = struct_titles[ "default" ]>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.