开发者

PHP template system, image paths

I'm making a basic templating system in PHP, the problem is:

I have a main request handler where from where everything is loaded and processed, but because of that the paths inside the CSS template I downloaded aren't correct anymore.

Example :

<img src="assets/images/contact.gif" />

has to be:

<img src="templates/grey-box/assets/images/contact.gif" />

Is there any way to fix this,开发者_如何学Go PHP wise?


Don't be lazy

  1. Always use an absolute path.

  2. Make it explicit, not with some dirty hacks. It will be a support nightmare.

  3. You can use some helper variables, like $tpl_assets_path and use it in the template.

Absolute path starts from / where / designates web-seite root. And every path on your HTML page should be.

So, the template should be either

<img src="/templates/grey-box/assets/images/contact.gif" />

or

<img src="<?=$tpl_assets_path?>images/contact.gif" />


define('HTTP_SERVER', 'http://www.myhomeurl.com/');
<img src="<?php echo HTTP_SERVER?>assets/images/contact.gif />


it's here

$imgarray = array('assets','script','css');
$tpl = '/templates/grey-box/';
foreach($imgarray as $i){
  $tpldir = $tpl.$i;
  $str = preg_replace("/([^\/])($i)([\/])/i","\$1$tpldir\$3",$str);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜