Page title

Reply

Join Date: Oct 2005
Posts: 25
Reputation: HostChart is an unknown quantity at this point 
Solved Threads: 0
HostChart HostChart is offline Offline
Light Poster

Page title

 
0
  #1
Oct 18th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 9
Reputation: e3computer is an unknown quantity at this point 
Solved Threads: 0
e3computer e3computer is offline Offline
Newbie Poster

Re: Page title

 
0
  #2
Nov 7th, 2005
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]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC