User Guide

184 Chapter 10 Reusing Code
<!--- 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 youre nested inside a loop --->
<cfset inloop = listfindnocase(ancestorlist,cfloop)>
<cfif inloop neq 0>
Im running in the context of a CFLOOP tag.<p>
</cfif>
<!--- Determine whether you are nested inside
a custom tag. Skip the first two elements of the
ancestor list, i.e., CFIF and the name of the
custom tag Im in --->
<cfset incustomtag = ’’>
<cfloop index=elem
list=#listrest(listrest(ancestorlist))#>
<cfif (left(elem, 3) eq cf_)>
<cfset incustomtag = elem>
<cfbreak>
</cfif>
</cfloop>
<cfif incustomtag neq ’’>
<!--- Say you are there --->
<cfoutput>
Im running in the context of a custom
tag named #inCustomTag#.<p>
</cfoutput>
<!--- Get the tag instance data --->
<cfset tagdata = getbasetagdata(incustomtag)>
<!--- Find out the tags execution mode --->
Im located inside the
<cfif tagdata.thisTag.executionmode neq inactive>
custom tag code either because it is in
its start or end execution mode.
<cfelse>
body of the tag
</cfif>
<p>
<cfelse>
<!--- Say you are lonely --->
Im not nested inside any custom tags. :^( <p>
</cfif>
</cfif>
3 Save the page as nestag2.cfm.
4 Open the file nesttest.cfm in your browser.