Solved

Creating path variable for images and  Include files

Posted on 2004-04-02
1
160 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
Comment Utility

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

762 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

11 Experts available now in Live!

Get 1:1 Help Now