Monday, June 23, 2008

Tags Used in CFML

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:
Application framework
Database manipulation
Data output
Exception handling
File management
Internet protocol
Page processing
Variable manipulation
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.
cfform: Similar to HTML forms, except that it allows developers to take advantage of automatically generated JavaScript validation provided by the ColdFusion 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: Performs if ... then ... else logic 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.
cfinput: Used in conjunction with the tag to take advantage of built-in JavaScript validation.
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 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 tag and evaluates passed expressions. This could be performed using a series of 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 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.