• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Application include header question

Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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>

TOPICS
Advanced techniques

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Feb 13, 2012 Feb 13, 2012

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

Votes

Translate

Translate
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

ok this is really weird.  That works too but it never sets the request.xyz to anything other than 5. findNoCase is not 0 in any case.  I dont understand that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

Okay, well try doing a <cfdump var="#request#" /> after the cfif statement. Where are you trying to reference the request.xyz variable?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

Owain Thank you so much. That is what I was looking for.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

Excellent, I thought it'd be that. Just goes to show you should never *assume* you know what's going on, *know* what's going on

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

TheScarecrow wrote:

Owain Thank you so much. That is what I was looking for.

What? To match the "start" in onRequestStart?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

The OP has never suggested he's trying to do that, I don't see why you'd ever have a header at the end of a page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2012 Feb 14, 2012

Copy link to clipboard

Copied

Owain North wrote:

The OP has never suggested he's trying to do that, I don't see why you'd ever have a header at the end of a page.

Header for onRequestStart, footer for onRequestEnd, and the expectation that the value of request.xyz should be 1 or 2, the implicit logic is all there. However, I agree with you it's only implicit, mostly padded by my imagination.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

Yes The code should have been.

<cfset currentPath = getBaseTemplatePath()>

           <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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2012 Feb 14, 2012

Copy link to clipboard

Copied

TheScarecrow wrote:

Yes The code should have been.

<cfset currentPath = getBaseTemplatePath()>

           <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>

Fair enough.  I would suggest instead

<cffunction name="onRequestStart">

<cfargument name = "targetPage" type="String" required="true">

<!--- Relative path: path from web root to requested page.--->

<!--- <cfset currentPath = arguments.targetPage> --->

<!--- Absolute path--->

<cfset currentPath = expandPath(arguments.targetPage)>

</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2012 Feb 14, 2012

Copy link to clipboard

Copied

You would suggest a mandatory argument in onRequestStart?  From where would that argument get passed?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2012 Feb 14, 2012

Copy link to clipboard

Copied

LATEST

Dan Bracuk wrote:

You would suggest a mandatory argument in onRequestStart?  From where would that argument get passed?

I don't suggest it, ColdFusion does. The argument gets passed by the caller of onRequestStart, namely, ColdFusion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2012 Feb 13, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation