When to Use #, and When Not To

Before we go any further, let’s clarify exactly when number signs are needed and when they’re not.

Simply put, number signs are needed to flag functions and variables within a string of text.

In this first example, the number signs are obviously needed:

Hello #VARIABLES.FirstName#

But what about when a variable is used within a tag, like this?

<cfset UpperFirstName=UCase(FirstName)>

Here number signs are not necessary because ColdFusion assumes that anything passed to a tag is a function or variable unless explicitly defined as a string. So the following is incorrect:

<cfset #UpperFirstName#=#UCase(FirstName)#>

This code will actually work (ColdFusion is very forgiving), but it is still incorrect and should not ...

Get Adobe ColdFusion 8 Web Application Construction Kit, Volume 1: Getting Started now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.