Programming instructions
Working with CFML expressions 21
One of the tags that ColdFusion provides to display output is the cfoutput tag. The
cfoutput tag instructs ColdFusion to process all the code between the cfoutput start
and end tags. The syntax for the
cfoutput tag looks like this:
<cfouput>
{normal html, text, and coldfusion processing instructions}
</cfoutput>
To return the value of a variable, you must always surround the variable name with
pound signs (#) and place the variable name between the
cfoutput start and end tags.
For example, the following code creates a variable and instructs the ColdFusion server to
return the value of the variable.
<cfset my_first_name = "Kaleigh">
<cfset my_last_name = "Smith">
<cfset my_full_name = variables.my_first_name & " " & variables.my_last_name>
<cfoutput>
#variables.my_full_name#
</cfoutput>
The following is the output:
Kaleigh Smith
Working with CFML expressions
Expressions are an important part of the ColdFusion language. Expressions are a
collection of different elements, ColdFusion variables, functions, and operators. You can
think of them as strings of text that consist of one or more of the following elements:
• Literal text (string), numbers, dates, and other values
• Variables
• Functions
• Operators (& for joining statements, + for addition, and so on)
Many examples of expressions were shown in this chapter; for example:
• #variables.my_full_name#
• DateFormat(Now())
• my_first_name= "Kaleigh"
When you build expressions in ColdFusion, you can include simple and complex
elements; how you represent these elements determines how ColdFusion processes your
program.
Building expressions
In ColdFusion, you build expressions as you need them. The expressions can include
simple elements, such as the expressions shown previously, or they can include complex
elements, such as arithmetic functions, strings, and decision operators. (You build some
complex expressions in Part II of this book.)