Solved

Creating path variable for images and  Include files

Posted on 2004-04-02
1
213 Views
Last Modified: 2013-12-24


when i needed to create a variable to determine the path, i've did the following:

<!---create rootpath variable on each page-->
<cfset rootpath = "../">

then called it like :

<img src="<cfoutput>#rootPath#</cfoutput>images/spacer.gif" width="780" height="1" alt="" border="0" /><br />

On my sites, the header and foother is often placed in an include file and then called on pages througout the site.  So if i set the rootpath in the page that was calling the include file, it would replace #rootPath# with " ../".

This works, however, i wanted to know is there a more efficient way to do this.   Can anyone give some help.  

Thanks,
Y


0
Comment
Question by:techiebabe
[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
1 Comment
 
LVL 5

Accepted Solution

by:
Seth_Bienek earned 200 total points
ID: 10743938

I use the statement below, because it allows me to use access the variable for templates in subdirectories as well:

<!--- Will set a string with the appropriate number of ellipses for a relative path reference. --->
<cfset request.relpath = repeatstring(".", listlen(cgi.script_name, "/")-2)>

The '-2' at the end indicates that the main folder for this app sits 2 folders deep from the web root.  This obviously can be left out if your application sits in your web root folder.

As far as efficiency goes, generally you trade efficiency for flexibility and robustness.   But either of these approaches (yours and mine) uses a negligible amount of server resources, so either is fine efficiency-wise.

Just as an added note, you may notice that I store the variable in the request scope.  This is so includes, custom tags, modules, etc. will have access to the variable as well.  It makes using custom tags which reference images much simpler to manage.

Take Care,

Seth
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

695 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