cf_buffer

My knowledge of ColdFusion 8 (or hell, even 7 for that matter) isn’t terribly broad. So if what I’m about to cover can be accomplished with an existing CF function or tag please let me know.

Output Buffering.

It’s something I first got use to with PHP. What it does is allow you to set a start and end point in your program and any output generated between those two points gets put into a variable which you can then manipulate further before outputting the content.

Recently I was asked if this was possible to do with ColdFusion. I couldn’t think of any existing feature that does this so I put together a (surprisingly) short custom tag that would do just that.

Here it is:

<cfif CompareNoCase( thistag.ExecutionMode, "start" ) EQ 0>
  <cfparam name="attributes.buffer" default="variables.buffer">
<cfelse>
  <cfset "caller.#attributes.buffer#" = thisTag.GeneratedContent>
  <cfset thisTag.GeneratedContent = "">
</cfif>

I put this into a file named buffer.cfm. Now anything that occurs between an opening and closing CF_BUFFER tag will be stored in a variable which can then be further manipulated however you want.

I did find something similar using getPageContext().getOut().getString(), but nothing simpler.

You might argue that this feature shouldn’t be needed in the first place. That whatever the need is it can be solved by redesigning the application. That might be true. But it’s a handy feature to play around with.

Advertisements

Color Usage Research Lab

The Color Usage Research Lab is sponsored by NASA and has a very informative website. They focus on… wait for it… color usage. A lot of information on how to choose colors and present them well in charts and graphs and such. Some of this might not be useful to a web developer, however they do have a section on Color Science which is amazingly useful and quite interesting.

Color science covers lots of stuff such as color perception, how the eye works, why certain colors don’t go together, color and legibility and so on.

So if you’ve got a couple hours to kill I highly suggest you check out color science.