Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFMODULE and images

Status
Not open for further replies.

Rayz66

Programmer
Sep 3, 2002
30
GB
Hopefully the last question for a while ... :)

Okay. I'm using a cfm file as a kind of layout template, which I call from another CFM file.

Code:
<cfset test= "test page"/>
<cfmodule template="templates/template.cfm">
<cfoutput>Hello! #test#</cfoutput>
</cfmodule>

Which works OK. But here's the problem. The images referenced in the template.cfm have to be relative to the calling template. And the calling template may be in any directory in the web app.

Is there a preferred way to make sure that the template.cfm can always reference the images directory, no matter where it is called from?

Thanks once again ... :)
 
Rather than...

../path/to/image

use

/full/path/to/image/

Or you could make a parameter of the custom tag to be the image location prefix...

Mind sharing the custom tag code? I'll see if I can help.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Ok.

The site is arranged like this

Code:
[root]
    Application.cfm
    documentview.cfm
    [images]
    [model]
        test.cfm
    [templates]
        template.cfm


The template is basically just putting the HTML around some content

Code:
<cfif thisTag.executionMode is "end">
<html>
<head>

<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="sheet.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#666666">
<img src="images/logo.jpg">
<cfoutput>#thisTag.generatedContent#<cfoutput>
</body>
</html>
<cfset thisTag.generatedContent=""/>
</cfif>

And I call the template in documentview.cfm, which is fine, but calling it from
test doesn't work, since the references to the images are wrong.
 
Great! Then there's no reason that adding a slash in front of images wouldn't fix it.

Code:
<cfif thisTag.executionMode is "end">
<html>
<head>

<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="sheet.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#666666">
<img src="[red][b]/[/b][/red]images/logo.jpg">
<cfoutput>#thisTag.generatedContent#<cfoutput>
</body>
</html>
<cfset thisTag.generatedContent=""/>
</cfif>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Mmmm .. that didn't work, but it gave me an idea for a fix.

I just set a variable

Code:
<cfset base="#CGI.SERVER_NAME#:#CGI.SERVER_PORT#/site">

Then I set a html base ref in the template.

Code:
<cfoutput><base href="#base#"></cfoutput>

Bit of a hack, but it seems to work OK ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top