Jump to content


This topic is now archived and is closed to further replies.


problem in template files

Recommended Posts

hi all,
i have created a template.tpl.php file in a folder in my project folder. this is basically a file which will hold my images etc and load them. i also have a image folder which has all my project images.i want to set the path of images in template file in such a way that whether i call that file from same directory or from any other folder, the images should load properly instead of path problem. the problem now is if i access it from some directory the images load properly but as soon as change the folder hierarchy there is display problem. to avoid this i was sending a querystring for the image path.but that is not a solution i feel.
Bhakti Thakkar

Share this post

Link to post
Share on other sites
Why not use an absolute URL instead of a relative URL?

If you put:
[code]<img src="http://www.example.com/images/myimage.png" />[/code]

instead of something like:
[code]<img src="../images/myimage.png" />[/code]

It shouldn't matter where the file's located.


Share this post

Link to post
Share on other sites
i had already coded the way you had suggested but i m facing the problem.  is there any way through which i can find out the base folder path in a variable so that i can store it in a variable and then i can dyamically pass the href  variable to the image tag i.e something like this:
<img src='<?=$ImagePath?>'> ???
I had already tried through $_SERVER['PHP_SELF'].But the problem is i am using 4.0.6 and this works only with 4.3.0 and above. Is there any alternative for $_SERVER['PHP_SELF']
Thanks in anticipation

Share this post

Link to post
Share on other sites
in your template file do something like:

<img src="{PREFIX}/images/myimage.png">

then while you set your tpl file and define your variables, set prefix as you want. define it as .. or templates/mytemplate or any other thing. It should solve your problem. And you can define it as a relative path and there wont be any problems according to the domain name.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.