Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Coldfusion Tips and Tricks

Written by CF FAN, March 13th, 2008
Careful use of # signs

The ## (pound) sign is very important in Coldfusion.

Code: ( text )
  1. <cfoutput>#variablename#</cfoutput>
is OK.

However using ## inside cfset and cfif tags is not good coding.

The following would be considered bad coding:
Code: ( text )
  1. <cfset var1=#variablename#>
  2. <cfif #variablename# eq "">


The ## sign are not necessary inside <cfif> and <cfset> tags because it takes more time to execute.

A good coding standard would be to avoid using pound signs around variables inside cfset and cfif tags:
Code: ( text )
  1. <cfset var1=variablename>
  2. <cfif  variablename eq ""></cfif>


A tidbit of information but valuable nonetheless.


cfinclude and custom tags

All of us are familiar with cfinclude and custom tags, both tags are used to include a file. What is the difference between them?

The main difference between cfinclude and custom tag is that the include tag works in a copy-paste manner. The scope of variables used in the calling page is available in the included page. But custom tags are individual ColdFusion pages, variables and other data are not automatically shared between a custom tag and the calling page, so we have to pass it as arguments.

Last edited by acoder : March 31st, 2008 at 03:28 PM. Reason: A few edits
2 Comments Posted ( Post your comment )
acoder / March 13th, 2008 03:34 PM
I've moved this to the Articles/howto section.

Thanks for posting this. The pound signs should only be used when necessary, so only surround the variables/functions that need them, not the whole text.
acoder / March 31st, 2008 03:31 PM
Rather than having small bits of info, one article with a collection of tips is more useful.

Stats:
Comments: 2