hal helm's logo  
home Home

training Training

writing Writings

code Code

tutorials Tutorials

newsletters Newsletters

consulting Consulting

Hal Helms logo
hal.helms

What Students Say...

"I was thrilled to have the opportunity to attend this course. It took some of the bits I've learned and reinforced it as a whole methodology." - Larry W

"The benefits of the course snuck up on me in the weeks after returning home, when I found myself using techniques I had learned almost without conscious thought. The overall experience of creating a web application and considering EVERYTHING - customer's business requirements, logical application structure, application code details - was invaluable." - Lisa W

"Once again, thanks for making this week a wonderful booster and inspiration for a lonely coder. It was wonderful to have you show the ins and outs of Fuseboxes and CF in general - can't wait to get back and put all those neato tips n' tricks to good use..." - Larry B

tutorials section

How can I create User-Defined Functions?

The Situation: You want to create your own functions to use across several CF pages


Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors

The Solution: We're all anxiously awaiting the debut of true UDFs in version 5. Until then, the best we can do is to create custom tags that can be used like functions. Never created a custom tag before? Don't worry -- it's the soul of simplicity. Let's create one now that produces management decisions. This is useful when you don't have a manager around to help you. We'll save it as "InstaMgr.cfm".

First, we'll create a new ColdFusion page that does what we want.


<!--- Create the universe of answers. --->
<cfset answer1 = "Hmmm...better let me think about it.">
<cfset answer2 = "Sorry, HQ put the kabosh on all new spending.">
<cfset answer3 = "Sounds like a personal problem.">

<!--- All parameters passed to the custom tag/function are referred to with an 
"attributes." prefix once within the scope of the tag. --->

<!--- ...to a manager all questions sound the same... --->
<cfset attributes.theQuestion = "Blah blah yadda yadda ho hum">

<!--- Select one... --->
<cfset num = RandRange(1,3)>

<!--- Return the answer to the caller. BTW, "caller." is the way you 
return info from a custom tag to the file that called it.--->
<cfoutput>
 <cfset caller.InstaMgr = "#Evaluate('answer' & num)#">
</cfoutput>

That's all there is to creating a custom tag. You can call it either with a <cf_ prefix (like <cf_InstaMgr>) or with a <cfmodule> tag. For example


<cf_InstaMgr 
  theQuestion = "Can we get some more resources on the mission critical project that must be done by next week?"> 
©copyright      designed by in-tuition.co.uk
hal helms' personal site Updates

Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors

teamallaire.com v 4_3