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 browser receives does not include the comment. Users cannot see the comment 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 nesting is useful if you want to temporarily disable a section of code while you test your application.
You can embed comments within comments, however, 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").

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