Jump to content


problem in template files

  • Please log in to reply
3 replies to this topic

#1 bhakti_thakkar

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 08 September 2006 - 11:47 AM

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

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 08 September 2006 - 12:46 PM

Why not use an absolute URL instead of a relative URL?

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

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

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

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 bhakti_thakkar

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 September 2006 - 05:06 AM

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

#4 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 11 September 2006 - 08:06 AM

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.
Roy Simkes
Yet Another Parkyeri Developer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users