Connecting Tech Pros Worldwide Forums | Help | Site Map

Coldfusion Tips and Tricks

Member
 
Join Date: Mar 2008
Location: INDIA
Posts: 50
#1   Mar 13 '08
Careful use of # signs

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

Expand|Select|Wrap|Line Numbers
  1. <cfoutput>#variablename#</cfoutput>
is OK.

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

The following would be considered bad coding:
Expand|Select|Wrap|Line Numbers
  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:
Expand|Select|Wrap|Line Numbers
  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; Mar 31 '08 at 04:28 PM. Reason: A few edits



acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,592
#2   Mar 13 '08

re: Coldfusion Tips and Tricks


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's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,592
#3   Mar 31 '08

re: Coldfusion Tips and Tricks


Rather than having small bits of info, one article with a collection of tips is more useful.
Reply