Solved

How to set a variable based on a user selected folder / directory location of .cfm file

Posted on 2007-03-27
4
176 Views
Last Modified: 2013-12-16
Hello CF Experts,

I have a CF application that I would like to dynamically set an ID variable based on the folder location of the .cfm file.

So, in my application, I have folders named Category1, Category2, Category3 and so on.

In those folders, I have index.cfm.

I would like to set a (known) category ID based on the folder (category) that the user chooses.

The logic would go something like this.

If folder name Category1 is detected in URL, set this:
<cfif (detect folder name for Category1 in url)>
<cfset sectionID = "123456">
</cfif>
<cfif (detect folder name for Category2 in url)>
<cfset sectionID = "123457">
</cfif>

Again, we already know what the ID is going to be, which will corelate to the chosen category, we just need to have a way to detect the folder name on the site that they choose.  Of course, we could always hard code the categoryID in the URL on the category selection page, but we don't really want to do that here.  Our main page is not dynamic in nature, and we are fine with that.

Thanks in advance for any help!
0
Comment
Question by:dstjohnjr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 18802337

this function will give you your folder location..
  getBaseTemplatePath()

This will tell you the folder

 <cfset dir =  ListLast(getDirectoryFromPath(getCurrentTemplatePath()),"/")>

Then use a switch

 <cfswitch expression="#dir#">
  <cfcase value="category1">
      <cfset sectionID = 12343>
  </cfcase>

 etc...

 
0
 

Author Comment

by:dstjohnjr
ID: 18802701
Ok, in this example, #dir# returns the full path (i.e. c:\cfusionmx7\wwwroot\category1\) to the location being browsed.

How do I test for a portion of the path in the cfcase code?  It works if I enter:

<cfcase value="c:\cfusionmx7\wwwroot\category1\">

but not just

<cfcase value="category1">

Also, you mention:

"this function will give you your folder location..
  getBaseTemplatePath()"

how do I implement this function?

Thanks for your help!
0
 

Author Comment

by:dstjohnjr
ID: 18803349
Ok, I actually figured this out on my own.  Here is the solution:

<cfset dir =  ListLast(getDirectoryFromPath(getCurrentTemplatePath()),"\")>
<!--- Start parsing and testing for the various cases based on our folder  --->
<!--- structure and then set the categoryID and variable based on our folder location --->
<!--- NOTE:  This code MUST be executed from within each folder you want to test for and NOT in an includes folder --->
 <cfswitch expression="#dir#">
<cfcase value="Category1" delimiters="\"  >
<cfset categoryID = 1001>
</cfcase>
<cfcase value="Category2 delimiters="\" >
<cfset categoryID = 1002>
</cfcase>
...and so on...
</cfswitch>

The problem was that initially, I did not have the delimiters property setup in the cfcase statement.  Once I added that, all is good!  Thanks for your help!  Although I ended up figuring it out on my own, you provided a great start and led me down the right path.  Thanks!
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 18803499

 glad you got it.

 The problem was the direction of the slash...
<cfset dir =  ListLast(getDirectoryFromPath(getCurrentTemplatePath()),"/")>

 should have been
 <cfset dir =  ListLast(getDirectoryFromPath(getCurrentTemplatePath()),"\")>
                                                                                                               ^^^^

 Glad you caught that small problem.


 However, in your cfcase statement, the delimiters parameter should be removed

  <cfcase value="Category1" delimiters="\">

 That parameter indicates the delimiter in the value clause, if there is a list such as this..

 <cfcase value="A|B|C|D" delimiters="|">

 Since you only have one value "Category1" the delimiter does nothing.

0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question