Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the html before you have the data

Status
Not open for further replies.

iamkillyou

Programmer
Jul 12, 2001
30
0
0
US
I think I need to redesign my entire site, but before I do that I'm asking here.

Every page on my site has a header/footer template which are called like this:

Code:
<!--- events.cfm --->
<cfinclude template="top.cfm">
<!---some layout stuff here--->
   <cfinclude template="a_events.cfm">
   <!---some more layout for the right side--->
   <cfinclude template="ads.cfm">
<cfinclude template="bottom.cfm">


Anyway my point is that a_events.cfm is what's going to do the queries and will eventually get the info like dates and locations that I'd like to put into the title, BUT the html title is set in the top.cfm template.

Javascript works - but that does me no good as I want the titles there for search engines to index.

I've tried adding this into my top.cfm template:

Code:
<cfset request.title = "site.com">
<cfparam name="title" default="#request.title#">
<title><cfoutput>#title#</cfoutput></title>

and in my a_events.cfm file:
Code:
<cfset request.title =  "this events details">

This however doesn't work as top.cfm is processed before a_events.cfm, so I'm outta ideas... Anyone else?

My website, or a bad habit?
BarSmart
 
this is going to come as a weird idea way out of left field, but how about you include a_events.cfm before top.cfm

r937.com | rudy.ca
 
Well I can't really cleanly include it first, because it has display data in it, and all of those templates before it are headers and other display stuffs, so they have to be before it.

I suppose I can include it first and save the generated content to a variable THEN place that variable where the include is now, more details on that working soon.

Thanks for the suggestion.

My website, or a bad habit?
BarSmart
 
ok cfsavecontent will work, but many hoops need to be jumped thru to return a title variable back to the calling template, deciding on if it's worth it to hack the code this way or to just start redesigning templates.

If anyone knows of a way to append to an html title server side, please let me know.

My website, or a bad habit?
BarSmart
 
OK here's the answer to the question:

Use cfhtmlhead

What you need to do is remove the title from your header template, and on all of your display templates do this:

Code:
<cfhtmlhead text="<title>mysite.com - whatever custom title you want with generated dynamic content in it</title>">
and it will insert the title right before the final
Code:
</head>
in the document.

My website, or a bad habit?
BarSmart
 
your top.cfm should have

<html>
<head>
<title>#page.title#</title>
<meta tags...#page.keywords#>
<meta tags...#page.description#>
</head>
<body>....

then to make it work use cfparam in your application.cfc/cfm to set the default values, then everywhere else...

<cfset page.title = "your page title">
<cfset page.keywords = "this that, etc...">
<cfset page.description = description of page">
<cfinclude template="top.cfm">

if you wan to populate the vars with db info from a_event.cfm, consider dividing your logic from your content, put your queries and cfml work above the top.cfm include, put your display / cfoutput below it, finish it up with the bottom.cfm

Kevin
 
You could just create a table in the database and have the page name (whatever.cfm), Title, Keywords, and Description stored there. Then use CGI variables to determine what page is being called by the browser and populate your html head from that. You can run that in your application.cfm/cfc before every page is loaded.


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
my first example was not very good.

here is a typical cfm page
---index.cfm---
run queries/ cfc calls, etc, work data down to a point that it is ready to display.

--- inc_head.cfm ---
html
head
title#pagetitle#/title
#meta#
/head
body
include top menu, left menu, etc...
--- end inc_head.cfm---

display data

--- inc_foot.cfm ---
footer links, info, etc.
/body
/html
--- end inc_foot ---

--- end index.cfm ---


This gives you FULL control over the contents of the html head.

Kevin
 
especially when you pull a lot of the HEAD stuff out of the database in the first place!!

like TITLE, METAs, the appropriate STYLEs and SCRIPTs, etc.

:)

r937.com | rudy.ca
 
cfhtmlhead is working really well for me.

Thanks a lot guys.

My website, or a bad habit?
BarSmart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top