Can someone show me how to do the equivalent of this function in Lucee.
“pageContext” is not valid string to getDeclaredField() method.

	Gets the path to the calling page.
<cffunction name="getCallerTemplatePath" output="false" returntype="string">
	<cfset var field = getMetaData(caller).getDeclaredField("pageContext")>
	<cfset field.setAccessible(true)>
	<cfreturn field.get(caller).getPage().getCurrentTemplatePath()>

What type do you get for caller if, for example, you do something like:

<cfdump var="#caller.getClass().getName()#">

I get this:


OK, so that one is

As you can see it does not have a field named pageContext, which explains the error message that you are seeing.

You have to always keep in mind that while Lucee does similar things as ACF, e.g. compile CFML to Java, etc., it does them differently. In this case you are looking for an internal variable of ACF in the Lucee code. You won’t find it.

If you have a valid use case then you can open a feature request/enhancement in the JIRA, and we can possibly provide a way to retrieve that information, but it would not be by adding a variable name to match the internal, undocumented, ACF code base.

1 Like

yes, I know that the PageContext is not a valid field in getDeclaredField.
I mentioned that in my post…

I was asking if anyone could help me to do the equivalent function in Lucee.

found what I was looking for:

<cffunction name="getParentTemplatePath" returntype="string" output="no">
    <cfset var stackTraceArr = getPageContext().getThread().getStackTrace() />
    <cfset var i = -1 />
    <cfset var thisFncFound = false />
    <cfset var currentFilePath = "" />
    <cfloop collection="#stackTraceArr#" item="i">
        <cfif right(stackTraceArr[i].getClassName(), 3) == "$cf">
            <cfif not thisFncFound>
                <cfset thisFncFound = true />
            <cfelseif len(currentFilePath) and stackTraceArr[i].getFileName() neq currentFilePath>
                <cfreturn stackTraceArr[i].getFileName() />
                <cfset currentFilePath = stackTraceArr[i].getFileName() />
    <cfreturn "" />
1 Like

Oh, so that’s what you’re trying to get… This built-in function will be much more efficient for you:


It returns an array of structs, of which you would want the value for the template key. e.g.