Returning Data

The caller scope passes data from inside a custom tag back to the calling template. Because custom tags exist within their own scope, you must use the caller scope if you want to make variables you create within your custom tag available to the calling template.

Setting a caller variable is just like setting any other type of ColdFusion variable. You may assign any datatype to a variable in the caller scope. This means that you can pass both simple and complex datatypes from inside a custom tag back to the template that called it.

Let’s create a quick example that demonstrates passing an attribute to a custom tag, acting on that attribute, and passing variables back using the caller scope. If you remember back to Chapter 13, you’ll recall that we created a CFML file for moving undeliverable email from the \undelivr folder to the \spool folder so that an attempt could be made to resend it. That template was actually based on a custom tag I wrote (and updated over the years) for the same purpose. Having the functionality as a custom tag makes it much easier to reuse the code. Example 21-3 shows the code from Chapter 13 rewritten as a custom tag called cf_resendundeliverablemailmx. Be sure to save the template as resendundeliverablemailmx.cfm on your server

Example 21-3. Resending undeliverable email

<cfsilent> <!--------------------------------------------------------------------------------- NAME: cf_resendundeliverablemailmx FILE: resendundeliverablemailmx.cfm CREATED: ...

Get Programming ColdFusion MX, 2nd Edition 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.