|
Using cfcontent to serve up Coldfusion generated CSS documents |
The article deals with using cfcontent to serve up dynamic data driven CSS. I'll use Coldfusion to embed variables in a cfm file, then use cfcontent to have the browser serve the content as a CSS file.
Whilst building the latest version of a framework I wrote a routine using cfsavecontent to generate a CSS document that had embedded Coldfusion variables in it. This was an effective way to generate dynamic CSS although it has left me in a position where the CSS is fully visible in the source code.To get around this I changed the code to this:
2<cfset variables.imglocation = "##00ffff">
3
4<cfoutput>
5/* CSS Document */
6
7* {margin:0px; padding:0px; border: 0px;}
8
9select,input,textarea{border-width: 1px; border-style: solid; border-color: grey;}
10
11.borderless{border: 0px;}
12
13a {color: 000;}
14
15body{font-family:Arial, Helvetica, sans-serif; font-size:12px;
16background-image:url(#variables.imglocation#/images/bgrd.jpg); background-repeat:repeat-x; background-color: ##ffffff;}
17</cfoutput>
The CSS is generated and the variables are embedded. Then the page is then processed by CF, but since the cfcontent sets the page to be served with a text/css mime-type the browsers recognizes the page as css. This means you can call the stylesheet just like normal.
http://scriptwriter.riaforge.org/
Thanks for the comments, and for the link. I'll go check it out, it may well prove that I end out using that.
I was going to look at actually writing a css file with coldfusion variables in it, but hadn't got that far yet.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef...