Coldfusion Tips and Tricks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CF FAN
    New Member
    • Mar 2008
    • 50

    #1

    Coldfusion Tips and Tricks

    Careful use of # signs

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

    [CODE=cfm]<cfoutput>#vari ablename#</cfoutput>[/CODE] is OK.

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

    The following would be considered bad coding:
    [code=cfm]<cfset var1=#variablen ame#>
    <cfif #variablename# eq "">[/code]

    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=cfm]<cfset var1=variablena me>
    <cfif variablename eq ""></cfif>[/code]

    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, 03:28 PM. Reason: A few edits
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

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

      Comment

      Working...