Custom Tags

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
The Next Step: Advanced ColdFusion Functionality


If there's not a ColdFusion tag that does what you need to do, you can create your own. If you find yourself using sections of code repeatedly or if there's a particular task you need to do often, such as validating an email address string or credit card number, you can create your own custom tag. Custom tags can encapsulate large amounts of ColdFusion functionality into a single, easy-to-use tag.

Custom tags typically are stored in the C:\CFusionMX\CustomTags directory and are then available to every application hosted on that server. If you do not have access to this directory (as in a commercial hosting environment), however, the tags also can be stored in the same directory as the template using the custom tag. You simply save your code template into the appropriate directory, and when you need to reference it, you do so by using a CF_ prefix.

For example, if you create a template to convert Fahrenheit to Celsius and you want to use this as a custom tag, save the Convert.cfm template into the appropriate directory. Then, in any other template, you can call the code by using the <CF_CONVERT TEMP="58"> tag. This is similar to CFINCUDE functionality, but you can include attributes, such as the TEMP attribute just mentioned. In addition, ColdFusion processing in custom tags happens independently of the calling template.

Many developers create and share these custom tags. You can find many free and commercial custom tags at the Macromedia Developer Exchange web site at http://devex.macromedia.com/. This web site is shown in Figure 4.

Figure 4. The Macromedia Developer Exchange web site.

graphics/apafig04.gif


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net