Obtaining Information from a parent Tag ColdFusion Help

You have examined how a child tag can share information with a parent tag. Let’s take things a bit further and have the Chi 1d tag grab information from the Parent again if and only if the Chi 1d is being wrapped. By using the Get Base Tag Data function we will show how a child can not only send information to the parent but also get information from the parent

listing 31.14 shows a modified Chi ld. efm that has the capability to get information from the parent tag. Listing 31.15 is a slight modification to Parent. efm. You need information for the child to get so this listing adds a new attribute Family name Finally Listing ~1.16 shows Tag Communieation Tag_2  efm a simple modification. You point to the new names of your custom tags and send a Faro;1yNameat~bute to the parent

The important change in Listing 31.14 has been bolded. (lIVedid not bold miscellaneous changes to reflect the new version of the code that is the _2 changes.) The added line <CFSETPARENT_DATA = GetBaseTagData( ‘CF]ARENT_2’ » grabs the data from the parent tag that has wrapped you. GetBaseTagData takes two attributes: the name of the tag (in this case CF_PARENT_2) and a number that reflects what instance of the wrapping tag you want to use. In this case the second attribute is not used. Let us explain that a bit further. Imagine this scenario:

<CF_Parent>
<CF_Parent>
<CF]aren~> .
<CF_Child>
</CF_Parent>
</CF_Parent>
</CF_Parent>

In this example, the child has multiple parents. If you wanted to get the second CF_Parent (or third) wrapping the inner CF_Chi 1d, you could specify so in GetBase- TagData. To get the second level wrapper above you, you would use <CFSET PARENT_ DATA=. GetBaseTagData( “CF]ARENT_2′ ,~». This tells you to get the second CF_Parent layer above you. To grab the third layer, you would simply change 2 to 3

When you called GetBaseTagData, you have the result saved into a structure called PARENT_DATAAt. that point, you can access the information just as you would any other structure. The code ‘Our Family Name is #Parent_Data. FAMILYNAMEd#i”splays the family name that is based on how CF_Parent is called. Now that you’ve seen the changes to the Chi 1d_2 custoin tag, let’s examine Listing 31.15.,

As before we have bolded the relevant changes to this tag: In this case, you have a simple attribute check on top of the document. You assign a variable called FAMILY NAME that is equal to the attribute sent in. If you don’t have one specified you use a default family name value. The only other change is also minor. After you output the fact that you are in the beginning of the tag, you output the family name as well. Listing 31.16 shows the calling template using the new names and attributes.

FIGURE 31.4

FIGURE 31.4

Using CFX Custom Tags

Because most developers will not create many CFX tags, we will not discuss that process in great detail. We will, however, discuss the tags in general and teach you how to install them on your Web servers.

The best way to think of CFX tags is as powerful, fast, custom tags. The main difference (and the reason for the additional power and speed) is that they are written in a compiled language such as C++, Delphi, or Java. Because they are written in a high-level language, however, it is not as easy to edit and debug them, For every change to a CFX tag, a new version must be compiled and saved to the server. Also, due to implementation differences, you may not be able to install a CFX if your Web site is on an 15P’s ,.~ server. Because they are based on the same set of ideas that custom tags are built on CFXs can do everything a simple custom tag can do. This includes accepting any number of attributes and returning any set of results. (The only thing CFXs can’t do is be used in an end-tag context; that is, you can’t use <CFX_Jedi> …</CFX_Jedi>.)

Due to their speed CFX tags can do things you would not want to do in a CFML custom tag. A perfect example of this is CFX_SpeTl, by Ben Forta. CFX_Spe” is a powerful custom tag that can easily and quickly add spell checking to your Web application. Although you could build a spell checker in standard CFML it would take an extremely long time to look up words in a dictionary. By using C++ as the underlying code the tag can run much more quickly

Implementing CFX Tags

CFX tags are typically distributed as DLL files. These are files that your computer will ‘ use to execute the custom tag. But before your ColdFusion server can use them, you must register them within the ColdFusion Administrator. After logging into the Administrator with your password select the CFX Tags menu option. This opens the Registered CFX Tags page shown in Figure 31.5

FIGURE 31.5

FIGURE 31.5

On the Registered CFX Tags page, you will see a list of all registered CFX tags. Each. CFX tag has a link to a details page and you will find an inputbox to enter .the name of a new tag. Let’s examine the details of one of the tags, CFX_GIFGD. Figure 31.6 shows the detailed information page for CFX_GIFGD.

FIGURE 31.6

FIGURE 31.6

Here you can make some important changes to the tag. First, you can change the name of the tag but if you do you need to make sure that every ColdFusion template page that calls this CFX is updated. Second, you can change the location of the DLL file. This field is important because it tells the server where to find the DLL. If this is not set correctly you will not be able to run the CFX tag

The next field, Procedure refers to the particular function within the CFX tag that will be called. This should always be ProcessTagRequest. The Keep Library Loaded setting determines whether the server should keep OLL in RAM. This could increase server performance if you think the CFX tag will be used a lot. The IMt field is a simple descrip- . tion field. It is there as a reminder in case you forget what a particular CFX tag does .

After you have registered a CFX tag, you can begin using it in your ColdFusion templates. Like standard custom tags, they are called via CF)CName. For example to call CFX_GIFDG, you would use: .<CFX_GIFGD OPTION1-‘Blah’ OPTION2-‘Foo’>.The attributes for a CFX tag will depend on the nature of the CFX tag. Check the documentation that came with the tag to learn the proper way to call them

Posted on November 17, 2015 in Building ColdFusion Custom Tag

Share the Story

Back to Top
Share This