View comments | RSS feed

Comments

ColdFusion comments have a similar format to HTML comments. However, they use three dash characters instead of two; for example:

<!--- This is a ColdFusion Comment. Browsers do not receive it. --->

The ColdFusion server removes all ColdFusion comments from the page before returning it to the web server. As a result, the page that a user browser receives does not include the comment, and users cannot see it even if they view the page source.

You can embed CFML comments in begin tags (not just tag bodies), functions calls, and variable text in number signs. ColdFusion ignores the text in comments such as the following:

<cfset MyVar = var1 <!--- & var2 --->>
<cfoutput>#Dateformat(now() <!---, "dddd, mmmm yyyy" --->)#</cfoutput> 

This technique can be useful if you want to temporarily comment out parts of expressions or optional attributes or arguments.

You can also nest comments, as the following example shows:

<!--- disable this code
<!--- display error message --->
<cfset errormessage1="Oops!">
<cfoutput>
#errormessage1#
</cfoutput>
--->

This is useful if you want to temporarily disable a section of code while you test your application.

You can embed comments within comments, however, you should use this technique carefully.

Note: You cannot embed comments inside a tag name or function name, such as
<cf_My<!--- New --->CustomTag>. You also cannot embed comments inside strings, as in the following example: IsDefined("My<!--- New --->Variable").


ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


Ashish-Saxena said on Jul 10, 2007 at 2:28 AM :
Note : Following lines ane only output (generated by .cfm file) not the code to run on browser.

<cfset my<!--- Name ---> = "Ashish Saxena">
<cfset N = "Name<!---Is --->"
my<!--- Name ---> = Ashish Saxena
<cfoutput>my#N#</cfoutput> = myName
<cfoutput>my#N# = #my# </cfoutput>
myName = Ashish Saxena

Comments can be embedded in side string as a string data type :
ToString("Ashish Saxena <!--- Is --->my name.") = Ashish Saxena my name.
Len("ABC DEF<!---GH--->IJ.") = 21
Replace("Ashish <!--- Saxena --->","<!--- Saxena --->","Gopa") = Ashish Gopa
Replace("Ashish <!--- Saxena --->","Saxena","Gopa") = Ashish
Replace("Ashish Saxena","<!--- Saxena --->S","*") = Ashish Saxena
ReplaceNoCase("Ashish Saxena","A","*","ALL") = *shish S*xen*

Comments can be embedded in side string as a function arguments,
where argument treated as string data type rather than,
function argument evaluate as a variable name.
For Example in UCase(String)
UCase(my<!--- Is --->) = ASHISH SAXENA
UCase("ashish<!--- saxena --->") = ASHISH

But , in function IsDefined(Variable_name)
evaluates a string value argument to determine whether the variable named in it exists,
and gives error as variable name does not contain any special character other than
_(underscore) and $(Unicode currency symbol).
ERROR :IsDefined("My<!--- New --->Variable")
ERROR :IsDefined("MyVariable<!--- New --->")
IsDefined("MyVariable"<!--- New --->) = NO

Whereas, in function Duplicate(Variable_name)
does not evaluates a string value argument as a variable_name.
Duplicate(my<!--- Name --->) = Ashish Saxena
Duplicate("Ashish <!--- Saxena --->") = Ashish
ERROR :Duplicate(m<!--- Name --->y) = <cfoutput>#Duplicate(m<!--- Name --->y)#</cfoutput>

Comments can be put before or(and) after the function name:
UCase<!--- IS --->("ashish <!--- saxena --->") = ASHISH
<!--- IS --->UCase<!--- IS --->("ashish <!--- saxena --->") = ASHISH
IsDefined<!--- New --->("MyVariable"<!--- New --->) = NO

But comments cannot be put inbetween function name:
ERROR :UCA<!--- as --->SE("ashish") = <cfoutput>#UCA<--- as --->SE("ashish")#</cfoutput>
ERROR :Is<!--- New --->Defined("MyVariable"<!--- New --->) = <cfoutput>#Is<!--- New --->Defined("MyVariable"<!--- New --->)#</cfoutput>

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000868.htm