PDA

View Full Version : unable to call external css, embeded css works fine.


Rakish
08-07-2006, 05:15 PM
Hi all,

I am having a hard time linking a css file to a template when using the HTML::Template Module.

Here is what i have:

1) myserver/cgi-bin folder, which has all the .pl files.
2) myserver/html folder, which has the template, CSS and html files

the template files have extension .tmpl

If i call an external CSS file like below:

<html>

<head>

<title>CssCreator-->HTML 4.01 Strict Template</title>

<meta http-equiv="content-type" content="text.tmpl;charset=utf-8" />

<meta name="generator" content="www.csscreator.com" />

<link rel="stylesheet" href="test.css" type="text/css" />



It doesnt work,

but if i embed the same CSS code in the:


<head>

<style>
css code
</style>

</head>

then it works fine.

I have tried my best, and i dont want to give up on it.

Please help.

Thankyou so much.

Rakesh Gupta

KevinADC
08-07-2006, 06:11 PM
use the full url to the css file:

href="http://mysite.com/test.css"

Rakish
08-07-2006, 06:34 PM
Thankyou Kevin,

You saved me from giving up, It works fine now....

but do you know the reason why it was happening?? As when i access the css from just an html file that doesnt get any input from perl (HTTP::Template) it works fine.

Thankyou once again,

I appreciate it

Rakesh

KevinADC
08-07-2006, 08:13 PM
when you do this:

href="test.css"

the server/browser thinks the file being linked to is in the same folder as the file being displayed. If your pages (the tmpl files) are being displayed from the script which might reside in the cgi-bin folder, the server/browser thinks the test.css file is also in the cgi-bin folder.

But even if it was in the cgi-bin it would not work because the cgi-bin is blocked from normal access, usually only scripts will work when linked directly to the URL, but other files, such as html or css or images will be blocked from being sent to the browser.

Using the full url points the browser to the real location of the css file and since it's in a folder that allows web access, the server sends the file back to the browser.

Rakish
08-07-2006, 08:16 PM
Got it....

THANKYOU,

GOD BLESS YOU

FishMonger
08-07-2006, 08:46 PM
One problem with using the full url is that it could be slower because it needs to do a DNS querry. I think it's better to use the proper relative path.

Here's a simple test I ran and which worked.
<html>
<head>
<title>Test Template</title>
<link rel="stylesheet" href="../../test.css" type="text/css" />
</head>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>

#!c:/perl/bin/perl -w
use HTML::Template;

# open the html template
my $template = HTML::Template->new(filename => '../htdocs/test.tmpl');

# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});

# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
body {background-color: yellow}

KevinADC
08-07-2006, 10:58 PM
yes, you can almost always use a relative path by adding ../ as many times as needed. I wasn't aware using the full URL might be slower, but maybe it is. Might be worth checking into.