Jump to content

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.
PLEASE DO GUIDE ME IN THIS
>:(
Thanks
Bhakti Thakkar
Link to comment
https://forums.phpfreaks.com/topic/20111-problem-in-template-files/
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.

Regards
Rich
hi,
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
BhaktiThakkar
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.