Skip to main content
Known Participant
February 13, 2012
Answered

Application include header question

  • February 13, 2012
  • 2 replies
  • 3113 views

Can you put onRequestStart something like this so it loads the correct header.cfm?  (yes this sample is setting a variable I know for a header I would have to use include)

At the moment on the pages show 5 and I am not sure why.  Does it not know that page path that is being requested?

<cfset currentPath = getCurrentTemplatePath()>

           <cfif findnocase("end", currentPath) GT 0>

                     <cfset request.xyz = 1>

            <cfelseif findnocase("start", currentPath) GT 0>

                     <cfset request.xyz = 2>

           <cfelse>

                     <cfset request.xyz = 5>

           </cfif>

This topic has been closed for replies.
Correct answer Owainnorth

I am trying to reference it on the individual pages.  ok I found the problem.  The currentpath is to the application not to the page being requested.  So how do I get it to set it to the page being requested?


I suspect you're after the getBaseTemplatePath() function.

2 replies

BKBK
Community Expert
Community Expert
February 13, 2012

TheScarecrow wrote:

Can you put onRequestStart something like this so it loads the correct header.cfm?  (yes this sample is setting a variable I know for a header I would have to use include)

At the moment on the pages show 5 and I am not sure why.  Does it not know that page path that is being requested?

<cfset currentPath = getCurrentTemplatePath()>

           <cfif findnocase("end", currentPath) GT 0>

                     <cfset request.xyz = 1>

            <cfelseif findnocase("start", currentPath) GT 0>

                     <cfset request.xyz = 2>

           <cfelse>

                     <cfset request.xyz = 5>

           </cfif>

I hope you're not expecting this code to tell you whether you're in onRequestStart or in onRequestEnd. OnRequestStart and onRequestEnd are methods in Application.cfc. They cannot be accessed using getCurrentTemplatePath().

If you put getCurrentTemplatePath() in OnRequestStart, it will register the path to your Application.cfc file. Your code will then register the value request.xyz = 1 or 2 only if the path to your application file contains "start" or "end". For example,

C:\ColdFusion9\wwwroot\workspace\render\Application.cfc

C:\ColdFusion9\wwwroot\startDir\Application.cfc

Owainnorth
Inspiring
February 13, 2012

Why don't you try outputting getCurrentTemplatePath() to find out?

Known Participant
February 13, 2012

ok so when output getCurrentTemplatePath() I get the correct path however it does not see the "end" or "start" in it and I am not sure why. Any ideas?

Owainnorth
Inspiring
February 13, 2012

Personally I'd try outputting findNoCase("end", currentPath) to the screen and hitting the various pages, see what you come up with.