Creating Your Own Tags With Cold Fusion
Extending HTML with CFML
By Leon Chalnick
It's difficult to write reusable code in the tag-based world of HTML. However, Cold Fusion enables you to create your own custom tags, which can have their own attributes and return values to the calling template.
Cold Fusion is a 32-bit, multiprocessing application server that runs in the Windows NT and UNIX environments alongside your Web server. Because it works with a wide variety of Internet standards (HTTP, SMTP, LDAP, and so on), Cold Fusion makes it easy to integrate databases into Web sites and intranet applications.
Custom Cold Fusion tags can be developed either in Cold Fusion Markup Language (CFML) or in C++, by including Cold Fusion API (CFAPI) components in your program. In addition to enhancing speed, CFAPI tags can call third-party DLLs and perform other advanced functions.
This article, however, focuses on CFML-based tags, which don't require C++ programming knowledge and can be passed parameters (that is, have their own attributes) and return values in the calling CFML template. In your custom tag code, you use the Attributes variable scope to address your tag's attributes, and the Caller variable scope to create variables in the calling template. The advantage of custom tags over older code-reuse methods (like <CFINCLUDE> tags) is that variables defined in the custom tag and Attributes variables are scoped to the custom tag. CFML tags can be scoped to an individual application (by including the tag in that application's directory tree) or to the entire server (by including the template in the CFusion/CustomTags directory).