184
3
4
<!--- 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're nested inside a loop --->
<cfset inloop = listfindnocase(ancestorlist,'cfloop')>
<cfif inloop neq 0>
I'm 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 I'm 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>
I'm running in the context of a custom
tag named #inCustomTag#.<p>
</cfoutput>
<!--- Get the tag instance data --->
<cfset tagdata = getbasetagdata(incustomtag)>
<!--- Find out the tag's execution mode --->
I'm 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 --->
I'm not nested inside any custom tags. :^( <p>
</cfif>
</cfif>
Save the page as nestag2.cfm.
Open the file nesttest.cfm in your browser.
Chapter 10 Reusing Code
Need help?
Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?
Questions and answers