• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

20. User-Defined Functions > 20.2. Calling User-Defined Functions

Calling User-Defined Functions

Regardless of whether you are dealing with a tag- or script-based UDF, you call it the same way you do any other CFML function—within a cfoutput block, within a cfset tag, in any tag attribute, and within CFScript code:

<cfoutput>
  #MyFunction("test", 12)#
</cfoutput>
   
<cfset x = MyFunction( )>
   
<cfmytag value="#MyFunction('test')#">
   
<cfscript>
  x = MyFunction(MyOtherFunction( ));
</cfscript>

The simplest way to call a UDF is to define it, then call it in the same template. A function defined in the template in which it is called may be defined anywhere on the page, including after it has already been referenced (ColdFusion parses the entire page before processing the instructions). If you use this method, you should define all functions at the top of the page for readability and consistency. Using one of the Mean( ) functions we created, you can define it inline and call it like this:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint