Solved

Creating path variable for images and  Include files

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WCAG audit tools 1 122
WEB Farm 6 85
.php tree directory? 5 95
Unexpected End of File 11 86
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…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

734 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