User Guide

Table Of Contents
Nesting custom tags 257
Example: ancestor data access
This example creates two custom tags and a simple page that calls each of the custom tags. The
first custom tag calls the second. The second tag reports on its status and provides information
about its ancestors.
To create the calling page:
1.
Create a ColdFusion page (the calling page) with the following content:
Call cf_nesttag1 which calls cf_nesttag2<br>
<cf_nesttag1>
<hr>
Call cf_nesttag2 directly<br>
<cf_nesttag2>
<hr>
2.
Save the page as nesttest.cfm.
To create the first custom tag page:
1.
Create a ColdFusion page with the following content:
<cf_nesttag2>
2.
Save the page as nesttag1.cfm.
To create the second custom tag page:
1.
Create a ColdFusion page with the following content:
<cfif thisTag.executionmode is 'start'>
<!--- Get the tag context stack. The list will look something like
"MYTAGNAME, CALLINGTAGNAME, ..." --->
<cfset ancestorlist = getbasetaglist()>
<!--- Output your own name. You are the first entry in the context stack.
--->
<cfoutput>
<p>I'm custom tag #ListGetAt(ancestorlist,1)#</p>
<!--- output all the contents of the stack a line at a time --->
<cfloop index="loopcount" from="1" to="#listlen(ancestorlist)#">
Ancestorlist entry #loopcount# n is
#ListGetAt(ancestorlist,loopcount)#<br>
</cfloop><br>
</cfoutput>
<!--- Determine whether you are nested inside a custom tag. Skip the first
element of the ancestor list, i.e., the name of the custom tag I'm in --->
<cfset incustomtag = ''>
<cfloop index="elem"
list="#listrest(ancestorlist)#"
<cfif (left(elem, 3) eq 'cf_')>
<cfset incustomtag = elem>
<cfbreak>
</cfif>
</cfloop>