Home > php教程 > php手册 > body text

PHP常规模板引擎中与CSS/JSON冲突的解决

WBOY
Release: 2016-06-06 19:47:47
Original
1238 people have browsed it

主要针对对象:Smarty/Dwoo 参考:http://developer.51cto.com/art/201009/224929.htm 其实以前都不怎么关注模板引擎,觉得没必要使用。但随着年龄的增加,代码洁癖越来越严重,才开始碰到这个问题。 Smarty和CSS/JS的语法存在冲突,因为二者都需要使用大括

主要针对对象:Smarty/Dwoo

参考:http://developer.51cto.com/art/201009/224929.htm

其实以前都不怎么关注模板引擎,觉得没必要使用。但随着年龄的增加,代码洁癖越来越严重,才开始碰到这个问题。

 

Smarty和CSS/JS的语法存在冲突,因为二者都需要使用大括号{}。虽然可以改Smarty的界定符,但你在一个现存系统中,去修改所有相关代码,是不划算的。

 

1. 避免同时出现

通过外部引用的方式避免。问题是避无所避。所以这种情况只适合少量简单的情况。

 

2. 修改Smarty界定符

 

2. 使用Smarty的literal标记将样式表信息包围起来

PHP常规模板引擎中与CSS/JSON冲突的解决

 
 
<title>{$title}</title> 
{literal}  
<styletypestyletype> 
p{  
margin::2px  
}  
 
{/literal}  
 </styletypestyletype>
Copy after login

PHP常规模板引擎中与CSS/JSON冲突的解决

PHP常规模板引擎中与CSS/JSON冲突的解决

<script type="text/javascript">
      function goods_show(id){<br /><br /><!--{literal}--><br /><br />art.dialog.open(url,{id:'select',title:'的:',width:760,height:380,padding: '10px'});<br /><br /><!--{/literal}-->
    }
</script>
Copy after login

PHP常规模板引擎中与CSS/JSON冲突的解决

 

第三种无疑是绿色环保的,在遇到冲突的地方,加上literal标记包裹。

该方案对Dwoo引擎同样有效。

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!