944,178 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Unsolved
  • Views: 4356
  • ColdFusion RSS
Oct 18th, 2005
0

Page title

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
HostChart is offline Offline
25 posts
since Oct 2005
Nov 7th, 2005
0

Re: Page title

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.
[HTML]<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>


[/HTML]

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


[HTML]<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>




[/HTML]
Reputation Points: 11
Solved Threads: 0
Newbie Poster
e3computer is offline Offline
9 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: conditional database query
Next Thread in ColdFusion Forum Timeline: cold fusion administrative access





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC