Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 155

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Using custom CFML tags
Custom tags written in CFML behave like ColdFusion tags. They can do all of the following:
• Take arguments.
• Have tag bodies with beginning and ending tags.
• Do specific processing when ColdFusion encounters the beginning tag.
• Do processing that is different from the beginning tag processing when ColdFusion encounters the ending tag.
• Have any valid ColdFusion page content in their bodies, including both ColdFusion built-in tags and custom tags
(referred to as nested tags), or even JSP tags or JavaScript.
• Be called recursively; that is, a custom tag can, if designed properly, call itself in the tag body.
• Return values to the calling page in a common scope or the Variables scope of the calling page, but custom tags do
not return values directly, the way functions do.
Although a custom tag and a ColdFusion page that you include using the
they differ in how they are processed. When a page calls a custom tag, it hands processing off to the custom tag page
and waits until the custom tag page completes. When the custom tag finishes, it returns processing (and possibly data)
to the calling page; the calling page can then complete its processing. The following image shows this process. The
arrows indicate the flow of ColdFusion processing the pages.
<html>
<head>
<title>Title</title>
</head>
<body>
<h3>The date is:</h3>
<cf_now>
</body>
</html>
MyPage.cfm
Calling custom CFML tags
Unlike built-in tags, you can run custom CFML tags in the following three ways:
• Call a tag directly.
• Call a tag using the
cfmessagebox
• Use the
tag to import a custom tag library directory.
cfimport
To call a CFML custom tag directly, precede the filename with
angle brackets (<>). For example, use the following line to call the custom tag defined by the file mytag.cfm:
<cf_myTag>
If your tag takes a body, end it with the same tag name preceded with a forward slash (/), as follows:
<cfif IsDefined("Attributes.Type")>
<cfif Attributes.Type IS "Date">
<cfoutput>#DateFormat(Now())#<cfoutput>
<cfelseif Attributes.Type IS "Time">
<cfoutput>#TimeFomat(Now())#<cfoutput>
<cfelse>
<cfoutput>#Now()#<cfoutput>
</cfif>
<cfelse>
<cfoutput>#Now()#</cfoutput>
</cfif>
Now.cfm
tag.
_, omit the .cfm extension, and place the name in
cf
Last updated 1/20/2012
tag are both ColdFusion pages,
cfinclude
150

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents