• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

21. Creating Custom Tags > 21.4. Returning Data

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


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint