Trace patterns called in ColdFusion

How do you track template path in ColdFusion?

those. 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 is equal to:

  • '/ Foo / bar /'
  • '/ Foo /'
  • '/'

How can I do this without a special declaration for the name of each folder?

+4
source share
2 answers

Take a look:

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

If you want a 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 result in the export of all templates passed to this call.

+8
source

Not perfect, but it 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 )>
+2
source

All Articles