Solved

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

Posted on 2007-03-27
4
166 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now