ColdFusion tags tell the ColdFusion Server that it must process information. The ColdFusion Server only processes tag contents; it returns text outside of ColdFusion to the web server unchanged. ColdFusion provides a wide variety of built-in tags and lets you create custom tags.
ColdFusion tags have the same format as HTML tags. They are enclosed in angle brackets (< and >) and can have zero or more named attributes. Many ColdFusion tags have bodies; that is, they have beginning and end tags with text to be processed between them. For example:
<cfoutput>
Hello #YourName#
! <br></cfoutput>
Other tags, such as cfset
and cfftp
,never have bodies; all the required information goes between the beginning (<) character and the ending (>) character, as in the following example:
<cfset YourName="Bob">
Sometimes, although the tag can have a body, you do not need to put anything in it because the attributes specify all the required information. You can omit the end tag and put a forward slash character before the closing (>) character, as in the following example:
<cfexecute name="C:\winNT\System32\netstat.exe" arguments = "-e" outputfile="C:\Temp\out.txt" timeout = "1" />
Note: The cfset
tag differs from other tags in that it has neither a body nor arguments. Instead, the tag encloses an assignment statement that assigns a value to a variable.
Over 80 built-in tags make up the heart of ColdFusion. These tags have many uses, including the following:
Much of this document describes how to use these tags effectively. CFML Reference documents each tag in detail.
ColdFusion lets you create custom tags. You can create two types of custom tags:
Custom tags can encapsulate frequently used business logic or display code. These tags enable you to place frequently used code in one place and call it from many places. Custom tags also let you abstract complex logic into a single, simple interface. They provide an easy way to distribute your code to others; you can even distribute encrypted versions of the tags to prevent access to the tag logic.
Currently, over 1,000 custom tags are available on the Macromedia developer's exchange (http://www.coldfusion.com/Developer/Gallery/index.cfm). They perform tasks ranging from checking if Cookies and JavaScript are enabled on the client's browser to moving items from one list box to another. Many of these tags are free and include source code.
When you write a custom tag in CFML, you can take advantage of all the features of the ColdFusion language, including all built-in tags and even other custom tags. CFML custom tags can include body sections and end tags. Because they are written in CFML, you do not need to know a programming language such as Java. CFML custom tags provide more capabilities than user-defined functions, but are less efficient.
For more information on CFML custom tags, see Chapter 10, "Creating and Using Custom CFML Tags". For information about, and comparisons among, ways to reuse ColdFusion code, including CFML custom tags, user-defined functions, and CFX tags, see Chapter 8, "Reusing Code in ColdFusion Pages".
CFX tags are ColdFusion custom tags that you write in a programming language such as Java or C++. These tags can take full advantage of all the tools and resources provided by these languages, including their access to runtime environments. CFX tags also generally execute faster than CFML custom tags because they are compiled. CFX tags can be cross-platform, but are often platform-specific, for example if they take advantage of COM objects or the Windows API.
For more information on CFX tags, see Chapter 12, "Building Custom CFXAPI Tags".