Question

Using: CF10 and IIS7.5

I have a section within my website called "Bookings". It is located like this:

c:\inetpub\wwwroot\mysite\bookings

Within this folder will be sub-folders and eventually webpages themselves. Heres an example:

c:\inetpub\wwwroot\mysite\bookings\holidays\new.cfm
c:\inetpub\wwwroot\mysite\bookings\carhire\edit.cfm

I include (using <cfinclude>) another page within each webpage that displays different links depending on which page is calling it. All I want to know is the directory up to the "bookings" folder. Something like this (pseudo code):

<cfset whereAmI = #GetDirectoryFromPath(GetBaseTemplatePath())#>
 <cfif #whereAmI# EQ "C:\inetpub\wwwroot\mysite\bookings">
 <h1>Booking Section Links</h1>
 </cfif>

The above code works only if the user visits the bookings/index.cfm page of the "bookings" folder. But if they go to the bookings/holidays/new.cfm page, it is now in the holidays folder so the <h1> content will not appear. I really only want to check for any page that is in the bookings folder, even if it is within a subfolder within the bookings folder. A bit like in SQL where I could say IF #GetDirectoryFromPath(GetBaseTemplatePath())# LIKE 'c:\inetpub\wwwroot\mysite\bookings%' so it has a wildcard on the end.

I know this question is going to irritate the MVC framework advocates but please excuse me on this!

Was it helpful?

Solution

Here is a quick, easy way to solve your problem (may not work as system expands - but should get you started down the right path).

<cfset whereAmI = GetDirectoryFromPath(GetBaseTemplatePath())>
<cfif whereAmI CONTAINS "C:\inetpub\wwwroot\mysite\bookings">
   <h1>Booking Section Links</h1>
</cfif>

Note, I removed the # from inside the cfset and cfif you do not need them there.

You could even scale back the path to use just 'mysite\bookings'.

Ideally, this should be wrapped up into a function so that you can easily pass different paths into it to determine if you are on a given page. Or, possibly, even determine the 'parent' folder in onRequestStart in Application.cfc and set it as a request scope variable.

This will need to be tweaked if you run the code on a *nix based system.

OTHER TIPS

It is more easier with CGI variables. You can use "CF_TEMPLATE_PATH". Try this

<cfoutput>The value of CF_TEMPLATE_PATH is: </cfoutput><cfdump var="#CF_TEMPLATE_PATH#">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top