Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

Writing Output

To output the contents or results of a ColdFusion expression, you use the <cfoutput> tag. cfoutput is a paired tag, which means that it has both start and end tags. cfoutput tells ColdFusion to parse any text found between the tag pairs for variables and expressions that need to be evaluated. We’ll use the cfoutput tag in a variety of ways throughout the book; it is one of the most commonly used CFML tags. For now, let’s focus on how the cfoutput tag outputs simple variable values.

The following example creates a number of variables using cfset tags and then outputs the values of the variables within cfoutput tags:

<!--- Assign values to variables --->
<cfset x = 1>
<cfset y = x+2>
<cfset Name = "Rob">
<cfset z = Name>
<cfset Authenticated = true>
<cfset TheDate = DateFormat(Now( ),'mm/dd/yyyy')>
   
<!--- Output the variable values --->
<h2>Writing Output</h2>
<cfoutput>
x = #x#<br>
y = #y#<br>
Name = #Name#<br>
z = #z#<br>
TheDate = #TheDate#<br>
Authenticated = #Authenticated#<br>
</cfoutput>

Executing this template causes the value assigned to each variable to be output to the browser, as shown in Figure 2-3. Note the use of pound signs (#) in this example. ColdFusion uses pound signs to separate expressions from literal text. When ColdFusion encounters an expression surrounded by pound signs, it attempts to evaluate it.

Writing output using the cfoutput tag

Figure 2-3. Writing output using the cfoutput ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page