For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Developing Applications Help / 

Using number signs

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Number signs (#) have a special meaning in CFML. When the ColdFusion server encounters number signs in CFML text, such as the text in a cfoutput tag body, it checks to see if the text between the number signs is either a variable or a function.

Note: Number signs are also called pound signs.

Is so, it replaces the text and surrounding number signs with the variable value or the result of the function. Otherwise, ColdFusion generates an error.
For example, to output the current value of a variable named Form.MyFormVariable, you delimit (surround) the variable name with number signs:

<cfoutput>Value is #Form.MyFormVariable#</cfoutput>

In this example, the variable Form.MyFormVariable is replaced with the value assigned to it.
Follow these guidelines when using number signs:

  • Use number signs to distinguish variables or functions from plain text.
  • Surround only a single variable or function in number signs; for example, #Variables.myVar# or #Left(myString, position)#. (However, a function in number signs can contain nested functions, such as #Left(trim(myString), position)#.
  • Do not place complex expressions, such as{{ 1 + 2 }}in number signs. Although this is allowed in a cfoutput block, such as <cfoutput>One plus one is #1 + 1#</cfoutput>, doing so mixes logic and presentation.
  • Use number signs only where necessary, because unneeded number signs slow processing.
    For a description of using number signs to create variable names, see Using number signs to construct a variable name in assignments in Dynamic expressions and dynamic variables.

Using number signs in ColdFusion tag attribute values

You can place variables, functions, or expressions inside tag attributes by enclosing the variable or expression with number signs. For example, if the variable CookieValue has the value "MyCookie", the following line sets the cfcookie value attribute to "The value is MyCookie":

<cfcookie name="TestCookie" value="The value is #CookieValue#">

You can optionally omit quotation marks around variables used as attribute values as shown in the following example:

<cfcookie name = TestCookie value = #CookieValue#>

However, surrounding all attribute values in quotation marks is more consistent with HTML coding style.
If you use string expressions to construct an attribute value, as shown in the following example, the strings inside the expression use single quotation marks (') to differentiate the quotation marks from the quotation marks that surround the attribute value.

<cfcookie name="TestCookie2" value="The #CookieValue & 'ate the cookie!'#">

 

Note: You do not need to use number signs when you use the cfset tag to assign one variable's value to another value. For example, the following tag assigns the value of the oldVar variable to the new variable, newVar: <cfset newVar = oldVar>.

Using number signs in tag bodies

You can place variables or functions freely inside the bodies of the following tags by enclosing each variable or expression with number signs:

  • cfoutput
  • cfquery
  • cfmail
    For example:

<cfoutput>
Value is #Form.MyTextField#
</cfoutput>

<cfoutput>
The name is #FirstName# #LastName#.
</cfoutput>

<cfoutput>
The value of Cos(0) is #Cos(0)#
</cfoutput>

If you omit the number signs, the text, rather than the value, appears in the output generated by the cfoutput statement.
Two expressions inside number signs can be adjacent to one another, as in the following example:

<cfoutput>
"Mo" and "nk" is #Left("Moon", 2)##Mid("Monkey", 3, 2)#
</cfoutput>

This code displays the following text:
"Mo" and "nk" is Monk 
ColdFusion does not interpret the double number sign as an escaped # character.

Using number signs in strings

You can place variables or functions freely inside strings by enclosing each variable or expression with number signs; for example:

<cfset TheString = "Value is #Form.MyTextField#">
<cfset TheString = "The name is #FirstName# #LastName#.">
<cfset TheString = "Cos(0) is #Cos(0)#">

ColdFusion automatically replaces the text with the value of the variable or the value returned by the function. For example, the following pairs of cfset statements produce the same result:

<cfset TheString = "Hello, #FirstName#!">
<cfset TheString = "Hello, " & FirstName & "!">

If number signs are omitted inside the string, the text, rather than the value, appears in the string. For example, the following pairs of cfset statements produce the same result:

<cfset TheString = "Hello, FirstName!">
<cfset TheString = "Hello, " & "First" & "Name!">

As with the cfoutput statement, two expressions can be adjacent to each other in strings, as in the following example:

<cfset TheString = "Monk is #Left("Moon", 2)##Mid("Monkey", 3, 2)#">

The double-quotation marks around "Moon" and "Monkey" do not need to be escaped (as in ""Moon"" and ""Monkey""). This is because the text between the number signs is treated as an expression; it is evaluated before its value is inserted inside the string.

Nested number signs

In a few cases, you can nest number signs in an expression. The following example uses nested number signs:

<cfset Sentence = "The length of the full name is #Len("#FirstName# #LastName#")#">

In this example, number signs are nested so that the values of the variables FirstName and LastName are inserted in the string whose length the Len function calculates. 
Nested number signs imply a complex expression that can typically be written more clearly and efficiently without the nesting. For example, you can rewrite the preceding code example without the nested number signs, as follows:

<cfset Sentence2 = "The length of the full name is #Len(FirstName & " " & LastName)#">

The following achieves the same results and can further improve readability:

<cfset FullName = "#FirstName# #LastName#">
<cfset Sentence = "The length of the full name is #Len(FullName)#">

A common mistake is to place number signs around the arguments of functions, as in:

<cfset ResultText = "#Len(#TheText#)#">
<cfset ResultText = "#Min(#ThisVariable#, 5 + #ThatVariable#)#">
<cfset ResultText = "#Len(#Left("Some text", 4)#)#">

These statements result in errors. As a general rule, never place number signs around function arguments.

Using number signs in expressions

Use number signs in expressions only when necessary, because unneeded number signs reduce clarity and can increase processing time. The following example shows the preferred method for referencing variables:

<cfset SomeVar = Var1 + Max(Var2, 10 * Var3) + Var4>

In contrast, the following example uses number signs unnecessarily and is less efficient than the previous statement:

<cfset #SomeVar# = #Var1# + #Max(Var2, 10 * Var3)# + #Var4#>

 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices