Heim  >  Artikel  >  Backend-Entwicklung  >  Smarty-3.x模板中图片、CSS、JS的路径怎么替换

Smarty-3.x模板中图片、CSS、JS的路径怎么替换

WBOY
WBOYOriginal
2016-06-13 13:32:27758Durchsuche

Smarty-3.x模板中图片、CSS、JS的路径如何替换?
比如说index.dwt模板文件里面有句代码:
 Smarty-3.x模板中图片、CSS、JS的路径怎么替换  
也许你会认为这个图片可以显示出来,但是打开http://localhost/index.php,发现图片并未显示,图片的路径变成了http://localhost/images/logo.gif,而真正的路径应该是http://localhost/themes/default/images/logo.gif。还有模板文件里的js、css的路径都需要替换。

Smarty-3.x版本中该如何替换,把替换函数写在哪个位置上?
(Smarty-2.x的版本我知道,只是不知道Smarty-3.x版本的替换)

希望各位大哥帮忙一下!


------解决方案--------------------
Smarty-3.x 也还有这种问题么?
------解决方案--------------------
将路径赋给变量,src中直接写变量+文件名:

PHP code

<?php $img_path = dirname(__FILE__)."/images/";
//smarty只要加上assign和display两个方法就行
?>
<img  src="<?=%24img_path?>logo.gif" border="0" alt=" Smarty-3.x模板中图片、CSS、JS的路径怎么替换 " >
<br><font color="#e78608">------解决方案--------------------</font><br>定一个basepath常量,根据需要改
<br><font color="#e78608">------解决方案--------------------</font><br>楼主该睡了 <div class="clear">
                 
              
              
        
            </div>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn