Custom tags are often developed to perform a specific operation within an application. They can be written to supply interface elements and data for ColdFusion tags and functions.
CF_COUNTWORD, written by Rob Bilson, performs a well-defined function using just three CFSET tags to handle input, processing, and output. This tag replicates the function of an existing CFX tag written in C++ but it is easier to implement because it does not have to be explicitly registered. The code is well-commented and the author created a custom editor in VTML for the tag, making it easy for others to use.
<!--- set local variable to the passed attribute --->
<CFSET MyString = attributes.Mystring>
<!--- Get the number of words in the string by treating
the string as a list and using the space character as the
delimiter. Note that the tag assumes a single line string
where words are separated by one or more spaces --->
<CFSET WordsInString = ListLen(MyString, " ")>
<!--- return the count back to the calling template --->
<CFSET Caller.NumberOfWords = WordsInString>
|