Chapter 19. Creating Custom Tags

One of the most powerful features of ColdFusion is the ability to extend the core capabilities of the platform through components known as custom tags. Custom tags allow you to encapsulate code in a neat wrapper that can then be invoked from within any CFML template. Those familiar with other programming languages can think of custom tags as similar to subroutines or procedures.

There are two varieties of custom tags: custom CFML tags (referred to as custom tags) and CFX tags. Because developing CFX tags requires C++, Java, or Delphi experience, this chapter focuses on the development and use of custom tags, since they are written in CFML. A brief section at the end of the chapter discusses installing and calling CFX tags.

Getting Started

Custom tags are just like regular CFML templates and can contain any combination of CFML, HTML, and JavaScript code. What makes them different is how they are called and how they interact with the template that calls them. Custom tags allow you to pass attributes to them (just like other CFML and HTML tags), perform some sort of processing based on the attributes passed in, and can return data in the form of variables that can be used by the calling template in any number of ways. Let’s first look at the benefits of custom tags.

Why Custom Tags?

Right now, you are probably wondering about the specific types of situations that might warrant the use of custom tags. Here are four reasons to use custom tags in your ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.