If you want to get a good start on learning ColdFusion, look no further. This article covers a whole bunch of CFML tags and some basic functions. It is the first of two parts, and excerpted from chapter three of the book ColdFusion Web Development with Dreamweaver MX 2004, written by Jen and Peter deHaan et al. (Apress; ISBN: 1590592379).
Introduction to ColdFusion Markup Language - Tags Used in CFML (Page 2 of 7 )
Let's look at some of the tags that make up CFML. This section provides a quick overview of some of the most common tags and their use. This should give you a general idea of what ColdFusion MX 6.1 is capable of. Following later are descriptions and code snippets detailing how to use some of these tags in a ColdFusion page.
ColdFusion MX 6.1 has more than 100 CFML tags, which Macromedia's documentation breaks down into the following categories:
However, what's more important are the specific tags that you will discover you use every day in ColdFusion. Some of the more useful tags are:
<cfchart>: Generates charts on the fly in a variety of formats, including.jpeg,.png, and.swf(Flash).
<cfdirectory>: Performs directory management tasks and allows you to create, delete, rename, or list the contents of a directory.
<cfdump>: Displays the contents of a variable to the screen for debugging purposes. Variables can contain simple values such as strings and numbers, or complex data such as Recordsets and structures.
<cferror>: Tells ColdFusion how to handle errors that occur in your application.
<cffile>: Performs file-management tasks and allows you to read, write, delete, move, rename, or append data to files on the server.
<cfftp>: Allows ColdFusion to FTP files to and from remote FTP sites.
<cffunction>: Allows you to write your own custom functions using CFML tags.
<cfhttp>: Allows you to post variables to remote sites, or grab the contents of a file on a different server.
<cfif>: Performsif ... then ... elselogic in ColdFusion, running code only if certain conditions are met.
<cfinclude>: Embeds other HTML or CFML code into the current document. This allows developers to break up larger files and reuse certain code/functions throughout the site.
<cflocation>: Redirects the currently running page to a different page, or redirects users to a different site altogether.
<cfloop>: Allows you to loop over Recordsets and structures a defined number of times, or while a certain condition is true.
<cfmail>: Sends an e-mail to a single user or group of users.
<cfmodule>: Allows you to call your own custom tags with ColdFusion.
<cfoutput>: Used to output the value of a variable, or loop over a Recordset.
<cfparam>: Checks to see if a certain variable exists; if not, it creates the variable and assigns a default value. It can also be used to validate the data type of a variable.
<cfquery>: Used to pass SQL statements to a database.
<cfqueryparam>: Used within<cfquery>to insert dynamic values into a SQL statement.
<cfset>: Define the value of a variable.
<cfstoredproc>: Execute a stored procedure (if supported by your database of choice).
<cfswitch>: Passes control to a matching<cfcase>tag and evaluates passed expressions. This could be performed using a series of<cfif>tags, but this method saves space and simplifies things.
<cftry>: Monitors a block of ColdFusion code and tries to catch any errors that may occur. It is used in conjunction with the<cfcatch>tag.
ColdFusion also has a couple of special files that are triggered before or after every user request and can be used to hold site-wide variables or settings; we will look at these now.