Solved

Creating path variable for images and  Include files

Posted on 2004-04-02
1
184 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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