24
Chapter 2: CFML Basics
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 manual.)
As mentioned, it is important that elements are identified properly in your expression so that
ColdFusion processes them as expected, and you avoid unnecessary errors. When you write
expressions, consider the following coding practices:
•
Use of consistent character case
•
When to use number signs (#)
•
When quotation marks are needed
Specifying a consistent character case
Because the ColdFusion server is case-insensitive, you can write expressions using all uppercase,
all lowercase, or mixed case. However, for code readability and consistency, you should use the
same character case in all your programs. If you write your programs using the same case rules,
you might prevent errors from occurring when you combine CFML on a page with case-sensitive
languages, such as JavaScript.
Specifying number signs to denote functions or variables
In ColdFusion, you specify number signs (#) to denote functions and variables within a string of
text. You use number signs to show the results of the function or variable on the page. Number
signs instruct the ColdFusion server to evaluate the function (or variable) between the number
signs and display the value. The value of the function (or variable) appears in the browser as a
result.
The following are some common ways to use number signs:
•
In the following example, you include the number signs to return the value to a page:
<cfoutput> Hello #variables.my_first_name# </cfoutput>
If you omit the number signs, the text, not the value, appears on the page.
•
In the following example, you do not include the number signs because you are using the
cfset
tag to assign one variable’s value to another value:
<cfset my_full_name = variables.my_first_name & " " &
variables.my_last_name>
•
To display a number sign on a page, you must designate the number sign as a literal character.
You do this by using two number signs (##); for example:
<cfoutput>
##1: Your name.
</cfoutput>
The result is the following output:
#1. Your name.
Содержание COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 14: ...14 Chapter 1 Introducing ColdFusion MX...
Страница 38: ...38 Chapter 3 Database Fundamentals...
Страница 40: ......
Страница 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Страница 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Страница 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Страница 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Страница 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...