PHP模板系统、图像路径
我正在用 PHP 制作一个基本的模板系统,问题是:
我有一个主请求处理程序,所有内容都从这里加载和处理,但由于我下载的 CSS 模板内的路径不再正确。
示例:
<img src="assets/images/contact.gif" />
必须是:
<img src="templates/grey-box/assets/images/contact.gif" />
有什么方法可以解决这个问题吗?PHP 明智的吗?
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, PHP wise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要偷懒
始终使用绝对路径。
使其明确,而不是使用一些肮脏的技巧。这将是一场支持噩梦。
您可以使用一些辅助变量,例如
$tpl_assets_path
并在模板中使用它。绝对路径从
/
开始,其中/
指定网站根目录。HTML 页面上的每个路径都应该如此。
所以,模板应该是
或者
Don't be lazy
Always use an absolute path.
Make it explicit, not with some dirty hacks. It will be a support nightmare.
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
or
它在这里
it's here