Skip to main content
Inspiring
May 19, 2008
Question

How to get the page call stack

  • May 19, 2008
  • 12 replies
  • 1526 views
Is there any way to get a list of files used in building a single page? What I need is to be able to see what page called the custom tag from within that custom tag. Using getBaseTemplatePath doesn't work because it only shows the top level page, not the actual file that called the custom tag. Take the following structure for instance:
/webroot/mydir/myfile.cfm
/webroot/mydir/myincludes/includefile.cfm
/webroot/customtags/thecustomtag.cfm

If myfile.cfm cfincludes includedfile.cfm and then includefile.cfm calls thecustomtag.cfm, thecustomtag.cfm thinks myfile.cfm called it. Which is wrong, and a bit stupid.

I've tried the back door method:
<cfset objFactory = CreateObject( "java", "coldfusion.server.ServiceFactory" ) />
<cfset objDebugging = objFactory.GetDebuggingService() />
<cfset qEvents = objDebugging.GetDebugger().GetData() />
<cfdump var="#qEvents#">

But found out later that this only works with debugging turned on in CF admin AND no IP restrictions are set (unless the IPs for the clients are listed there).

This should be a very simple task, one would think. Any suggestions?
This topic has been closed for replies.

12 replies

Inspiring
May 19, 2008
Hmmm... not sure what you mean. Your snippet creates a structure key using the filename with version/license info. What I'm looking for is how to grab the path of the real calling file.

The problem is that cfincluded files don't expose the real calling page, but thinks it was called from the top level requested page. In your snippet, if you add :

TemplateManagement[myName].path = getCurrentTemplatePath();
TemplateManagement[myName].basepath = getBaseTemplatePath();

Then cfinclude that file from a cfincluded file you'll see what I mean.
Inspiring
May 19, 2008
We CFInclude the following snippet into all project files when this functionality is needed:

<CFScript>
//////////////////////////////////////////////////////////////////////////
//
// Init Template Management
//
myName = getFileFromPath(getCurrentTemplatePath());
if(NOT isDefined('TemplateManagement')){
TemplateManagement = structNew();
TemplateManagement.cnt = 0;
}
else{
TemplateManagement.cnt = TemplateManagement.cnt + 1;
}
if(NOT structKeyExists(TemplateManagement, myName)){
TemplateManagement[myName] = structNew();
}
//
// Versioning:
//
TemplateManagement[myName].App.Version.Major = 1;
TemplateManagement[myName].App.Version.Minor = 1;
//
// License:
//
TemplateManagement[myName].License.SerialNumber = '';
TemplateManagement[myName].License.Owner = '';
//
//
//////////////////////////////////////////////////////////////////////////
</CFScript>


...at the end of the http request, usually in onRequestEnd.cfm, you can grab the 'TemplateManagement' struct and take a look.