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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including css in the Application.cfm 1

Status
Not open for further replies.

ktownchik

Technical User
Mar 29, 2003
6
CA
hello :)

i'm probably using the completely wrong syntax but how do i include a styles.css into my Application.cfm file?

right now i have
<!---Include stylesheet--->
<cfinclude template=&quot;styles.css&quot;>

and all its doing is pasting my css to the top of the page - how can i embedd the file?

thanks!
!nina.
 
hi !nina

unless your styles.css template contains coldfusion code, which would be exceedingly rare but not unheard of, then what you want is to use a plain old LINK html tag

where do you generate the DOCTYPE, HTML, and HEAD tags? that's where you put the LINK tag, and then the browser can cache styles.css

rudy

 
thanks rudy :)
for both replies ;)
i just ended up using a link within the html - i figure i can embbed it later
 
your tag should look like this:

[tt]<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot;
ref=&quot;style.css&quot; />[/tt]

i don't think you want to &quot;embed it later&quot;

using a LINK tag allows the browser to cache the style sheet, so that it will not download on other pages that share that style sheet file, which would likely be most of the pages in your site

what did you mean by &quot;embed it later&quot;?
 
Why would you do this? The application.cfm is only a functional file - it will not be accessed by the user and therefore does not need to be formatted.
 
well i guess i just wanted to somehow make it so that i don't have to manually insert an html link into every page?
is there a way of doing this?

usually i use templates - but i'm still unsure of those with coldfusion.

as i said :) - i'm really new to this - i'm just teaching myself basic syntax this weekend.

can anyone suggest anything?

thanks again :p
 
can anyone suggest anything? yes

insert the LINK tag in the same place where you insert the TITLE, i.e. the HEAD

if that's a separate piece of code on every one of your pages, then that's how you have architected your source code, so you have to insert it once into all pages, but then at least you'll be done with it

tip: search & replace <HEAD> to <HEAD><LINK ... >

other people use a common template or some similar technique that is called on every page, which is why i suggested inserting it there would be easy

the only time it makes sense to do this in the application.cfm file is if you already generate every page's DOCTYPE and HEAD there

in my own site, i generate the DOCTYPE in application.cfm, but i do the HEAD in a CFINCLUDE template, because the TITLE is pulled from a database, and i don't want a database call in application.cfm, because there are several non-database but coldfusion pages which don't pull the TITLE from the database

plus, although it's not implemented yet, my common template also has stylesheet switcher and cookie logic, so i don't want to clutter that into application.cfm

so i don't generate the LINK in application.cfm, but in a common template that's included on every page which needs a stylesheet

this isn't really a &quot;coldfusion&quot; question so much as it is a question of how to architect the source code for all the pages in a site, pages which will obviously share some things, e.g. same logos, stylesheets....

rudy
 
I do believe that the HTML spec is such that a stylesheet should be recognized until it's within an <HTML> or <HEAD> tag (forget which)... so, supposedly, it wouldn't do any good to point it in the Application.cfm anyway (not that anybody really adheres to the HTML spec... so it would probably work regardless).

But, yeah, the whole idea of using <LINK> is so that you don't have to code the entire stylesheet in each page... and you only have one CSS to maintain.

But, barring that, you could certainly put your stylesheet in an .HTML or .CFM page and include it using CFINCLUDE. Could be gentler on older browsers that don't understand <LINK> anyway.


With regard to ColdFusion code in a stylesheet... I started doing this a little while back and I'll never go back to static stylesheets.
Old way: we had a styles directory with-
stylesheet_ie4.css
stylesheet_nn4.css
stylesheet_6up.css
stylesheet_mac.css
stylesheet_unix.css
stylesheet_unknown.css
etc.

Everytime I wanted to change the size or color of <H2> or my listitem class, I had to remember to go into each .css file and update it, keeping in mind all the stupid differences in font sizes, formatting, etc across the browsers.

Now I have one stylesheet that dynamically determines the platform and browser and adjusts everything accordingly. I only have to update one entry in one file. AND I can even utilized it in standard ole HTML pages... because the SSI still processes all the CFML before it includes it into the page.

-Carl
 
Carl,

I'd like to understand what you are doing here. I'm looking to database my CSS sheet so that I can present the values on a form for administration by non-techie users.

Can you use coldfusion in a css page?
 
Nope, you can only use ColdFusion on ColdFusion pages. You can use css on a ColdFusion page, though.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
carl hasn't been here in quite some time. this post is mid 2003. no you can't put CF in a CSS page unles you configure your cfadministrator to handle css pages but then it'll look at every css page and that's bad.

try:

styles.cfm
---------
Code:
<cfquery name = "qGetStyles" datasource = "dsn">
select *
from stylesTable
<cfoutput>
<style>
body {
color: #qGetStyles.bodyFontColor#;
background-color: #qGetStyles.bodyBackgroundColor#;
}
</style>
</cfoutput>
-----------



index.cfm
==========
Code:
<html>
<head>
<title>Hello</title>
<cfinclude template = "styles.cfm">
</head>
<body>
hi how are you
</body>
</html>
============


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
beat me to it ecobb.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top