Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become passionate about making software.

Ten ColdFusion 8 One-Liners

August 1, 2007

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!
variables.mystructure="{AL="Alabama",DC="District of Columbia"};

4. Create an array

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.
this.mappings["/mymap"] = getDirectoryFromPath(getCurrentTemplatePath());

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

No Comments

Some comments have been lost over the years due to moving hosts.


More blog entries that I have written.

Code coloring by PRISM.