DevWebProIN Newsletter:
Last Updated:


Get Your Site Submitted for Free in the World's Largest B2B Directory!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions


Dynamic Arguments & Attributes In ColdFusion

By Raymond Camden
Expert Author
Article Date: 2007-05-14

One of the announced features for ColdFusion 8 is support for dynamically passing attributes to ColdFusion tags.

This will be a godsend for tags like CFMAIL. A reader asked me (and by the way, folks, don't ask me about Scorpio, in general I can't answer) if this support carried over to cfmodule and custom tags.

This is actually something that has been supported in ColdFusion for quite some time. I don't have the exact version it was added to ColdFusion, but custom tags have had support for 'attributeCollection' for a while. Consider this simple custom tag:

<cfdump var="#attributes#" label="In the tag">

If you first run it like so:

<cf_customtag name="ray" age="34">

You will see a struct with 2 keys, name and age. However, you can get the same result like so:

<cfset s = structNew()>
<cfset s.name = "ray">
<cfset s.age = 34>
<cf_customtag attributeCollection="#s#">


At the same time, ColdFusion UDFs support an argumentCollection value. Consider this example:

<cffunction name="mirrorargs">
   <cfreturn arguments>
</cffunction>

<cfset result = mirrorargs(name='ray',age=34)>
<cfdump var="#result#">


This returns a structure much like the custom tag example. Now imagine we call it like so:

<cfset s = structNew()>
<cfset s.name = "ray">
<cfset s.age = 34>
<cfset result=mirrorargs(argumentCollection=s)>
<cfdump var="#result#" label="Result using argumentcollection">


This will return the same structure as well. (Although to be clear - the case of the structs keys is different, but you should not be relying on struct key case anyway.)

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact | Site Map

DevWebProIN is an iEntry, Inc.® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal
Dynamic Arguments Attributes in ColdFusion