Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you track templates calls in ColdFusion?

Tags:

coldfusion

How do you track template path in ColdFusion?

I.E. I have the following folder and file structure

  • index.cfm

    <cfset ArrayAppend(request.Trace, '/')> <cfdump var=#request.trace#>

  • foo

    • index.cfm

      <cfset ArrayAppend(request.Trace, '/foo/')> <cfinclude template='../'>

    • bar

      • index.cfm

        ArrayAppend(request.Trace,'/foo/bar/')> <cfinclude template='../'>

When I call foo/bar/index.cfm, request.Trace equals:

  • '/foo/bar/'
  • '/foo/'
  • '/'

How could I do this without specifically declaring each folder name?

like image 994
Marc Barbeau Avatar asked Dec 24 '22 05:12

Marc Barbeau


2 Answers

Have a look at:

  • expandPath(".")
  • getBaseTemplatePath()
  • getCurrentTemplatePath()
  • CGI.CF_TEMPLATE_PATH
  • CGI.PATH_TRANSLATED
  • CGI.SCRIPT_NAME

If you want the template stack trace, use this:

<cfset templateTrace = []>
<cfset tagTrace = createObject("java","java.lang.Exception").init().TagContext>
<cfloop array="#tagTrace#" index="tagInfo">
    <cfset templateTrace.add(tagInfo.Template)>
</cfloop>
<cfdump var="#templateTrace#">

This will output all templates passed up to this call.

like image 162
Alex Avatar answered Jan 08 '23 22:01

Alex


Not ideal but this worked for me.

<cfset currentFile = GetCurrentTemplatePath()>
<cfset currentDir = GetDirectoryFromPath(currentFile)>
<cfset webroot = expandPath("/")>
<cfset m_Trace = Replace(currentDir, webroot , '\')>
<cfset ArrayAppend (request.Trace, m_Trace )>
like image 34
Marc Barbeau Avatar answered Jan 08 '23 22:01

Marc Barbeau