This morning, I was playing around with a ColdFusion custom tag that would encapsulate the rendering of a
<select> menu. Part of this encapsulation involved propagating attributes from the ColdFusion custom tag onto the underlying Select element. As such, I randomly tried to pass a
data- attribute into the ColdFusion custom tag; and, it worked! I didn't know that this was possible with ColdFusion custom tags. Furthermore, it appears to work in both Lucee CFML and Adobe ColdFusion!
To demonstrate this, I'm going to create a ColdFusion custom tag that does nothing but
<cfdump var="#attributes#" /> <cfabort />
Then, I'm going to invoke this ColdFusion custom tag with a variety for attribute formats:
<cf_MyTag foo="bar" x:foo="bar" data-foo="bar"> </cf_MyTag>
This uses a "vanilla" attribute, a name-spaced attribute, and a dashed attribute. And, when we run this in both Lucee CFML and Adobe ColdFusion, we get the following output:
This is great! If I'm going to create some ColdFusion custom tags that encapsulate the rendering of HTML tags, it's nice to know that more of the attributes that I might pass into an HTML tag can also be passed into a ColdFusion custom tag.
ASIDE: I tried using some of the more esoteric attribute syntax that Angular uses, such as
[attr]="", but both ColdFusion runtimes throw an error with these formats.
Want to use code from this post? Check out the license.