0

Ten ColdFusion 8 One-Liners

ColdFusion 8

Whether you are spending time in a bar, chatting with friends or a programming language its always handy to have some good one liners. Here, in no particular order, are ten ColdFusion 8 one-liners:

1. Convert an image
ColdFusion converts an image based on the file extension in the source and destination attributes.
<cfimage destination="/misc/cf8.png" source="/misc/cf8.jpg" action="convert">

2. Combine PDFs
Provide a list of pdfs in the source attribute and they will be merged into one pdf.
<cfpdf destination="/misc/my.pdf" source="/misc/file1.pdf,/misc/file2.pdf" action="merge">

3. Create a structure
I love this new feature!
<cfset variables.mystructure="{AL="Alabama",DC="District of Columbia"}>

4. Create an array
Likewise
<cfset variables.myarray=["Homer","Lisa","Bart"]>

5. Loop over an array
Each item of the array gets assigned to the variable in index.
<cfloop index="variables.i" array="#variables.myArray#"></cfloop>

6. Loop over a file line by line
Each line of the file gets assigned to the variable in index. Even better ColdFusion reads the file line by line and does not put the file in memory. CF can now work with huge log files efficiently.
<cfloop index="variables.i" file="/misc/log.txt"></cfloop>

7. Add a RichTextArea
This will show just the basic toolset, replace that with Default, to see all the options. (Underneath this is FCKEditor)
<cftextarea name="comments" toolbar="Basic" richtext="true"></cftextarea>

8. Add a DateField
Produces a input box with a calendar icon and a completely html/JavaScript calendar.
<cfinput id="startdate" name="startdate" type="datefield">

 

9. Add a ColdFusion Mapping
Within Application.cfc this will add a completely dynamic mapping. I've blogged about this before.
<cfset this.mappings["/mymap"] = getDirectoryFromPath(getCurrentTemplatePath())>

10. Add a Custom Tag Path
Ditto the above for a custom tag path.
<cfset this.customtagpaths="getDirectoryFromPath(getCurrentTemplatePath())">

tags:
ColdFusion 8
David said:
 
Great stuff Sam - not sure how you whittled it down to only 10!

Cheers,

Davo
 
posted 441 days ago
Add Comment Reply to: this comment OR this thread
 
Dan Russell said:
 
This is a good teaser... I can't wait to upgrade.
 
posted 441 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Davo, I had quite a few more on the list, including autosuggest with cfinput, but tried to have only two from any one area and choose texarea and calendar for forms.
 
posted 441 days ago
Add Comment Reply to: this comment OR this thread
 
Ryan said:
 
Sam, sorry about the code snippits not working. I have a ticket in with the host!! They migrated my sites to new servers without my knowledge.
 
posted 441 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Ryan, Looks like its back and working now! :)
 
posted 441 days ago
Add Comment Reply to: this comment OR this thread
 
Ryan said:
 
Yea, sorry to cause you extra work Sam.

Ryan
 
posted 440 days ago
Add Comment Reply to: this comment OR this thread
 
Egze said:
 
Wow, I'm glad I don't have to work with ColdFusion. No offense :)
 
posted 440 days ago
Add Comment Reply to: this comment OR this thread
 
 
That is quite a profound comment there Egze. Thanks for the enlightenment, the likes of which I can only imagine that you offer to the world regularly. Perhaps if you have time, perhaps you could share some other things like "I like cheese" or "My shoes are brown".

:)
 
posted 439 days ago
Add Comment Reply to: this comment OR this thread
 
 
And btw.... great list Sam.
 
posted 439 days ago
Add Comment Reply to: this comment OR this thread
 
David said:
 
Hilarious! Egze does offer more prophetic advice on his own Blog though, Dave....Titled "How to be a better web developer".

It's filled with hot tips like: "Try new stuff", "listen to podcasts" and "learn English". Thanks Dude, I'll get right on that! He continues with "After you've read about something new on Digg or any other website, don't be afraid to try it out."

Unless that's ColdFusion, of course! Wouldn't want you to have to "work" at that one, would we?

But please, more nuggets of priceless life advice, at your convenience.

Davo
 
posted 439 days ago
Add Comment Reply to: this comment OR this thread
 
 
Egze, post up an example of how you would merge pdf docs with PHP. Maybe you have a faster way to write that?
 
posted 439 days ago
Add Comment Reply to: this comment OR this thread
 
Chris said:
 
Any idea how to get the date selector div to display over other input type = text boxes? When I have other form elements in the display region of the calendar, the calendar displays under them. Any ideas?
 
posted 425 days ago
Add Comment Reply to: this comment OR this thread
 
sohaib said:
 
When I worked with ColdFusion7 and Java I found that ColdFusion's Java integration was not up to the mark.
I wonder if this has changed in ColdFusion8.

As an example, in CF7 it was not possible to use the Java Collections, Iterators or Enumerators in CF tags and expect them to be treated like ColdFusion collections. Has this changed in CF8?


Thanks,
Sohaib
 
posted 399 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Sohaib: I have not done that much with Java and CF so have not looked into that.
 
posted 398 days ago
Add Comment Reply to: this comment OR this thread
 
Dan L said:
 
I'm new to ColdFusion, coming from a PHP background. I knew CF was a "rapid-development" sort of language, but good lord that's ridiculous simple code. Almost as ridiculous as the price tag. But every time I learn things like this, it gets a little more justified.
 
posted 390 days ago
Add Comment Reply to: this comment OR this thread
 
David said:
 
Dan, the "price" is something that gets talked about alot, both inside and outside of the ColdFusion community. If your main concern is an up-front payment, then stick with PHP.

Most companies, however, are concerned with the Total Cost of ownership, and there's no doubt, that your return on investment is easily and quickly recouped with ColdFusion.

Cheers,

David
 
posted 390 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Dan L: On Pricing: There are many pricing options. Starting at the cheapest there are at least 10 hosts offering CF for under $10/month, and then hosting options run the full spectrum. Depending on the host you will find CF is included or costs a little more extra per month.

If you are hosting yourself then take a look at the standard edition. It will be fine for a good number of applications. At the top end is running Enterprise yourself.

And the developer edition is always free.
 
posted 388 days ago
Add Comment Reply to: this comment OR this thread
 
Peter said:
 
nice 1. My last interview, for the company I work for now, one of the questions my manager asked was name 5 new things that CF 8 offers.

This will add to the list in case they ask again :)

Peter
 
posted 386 days ago
Add Comment Reply to: this comment OR this thread
 

Search

About Me
I am a 32-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and daughter. I work for Interfolio where we help people collect, deliver and showcase their life's work. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.