Home  >  Article  >  Backend Development  >  PHP针对常规模板引擎中与CSS/JSON冲突的解决方法_PHP

PHP针对常规模板引擎中与CSS/JSON冲突的解决方法_PHP

WBOY
WBOYOriginal
2016-05-31 19:30:301014browse

JSON

本文实例讲述了PHP针对常规模板引擎中与CSS/JSON冲突的解决方法,有一定的实用价值,具体分析如下:

本文主要针对对象为Smarty与Dwoo

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

1. 避免同时出现

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

2. 修改Smarty界定符

3.可以使用Smarty的literal标记将样式表信息包围起来,如下所示:

<html> 
<head> 
<title>{$title}</title> 
{literal} 
<styletypestyletype="text/css"> 
p{ 
margin::2px 
} 
</style> 
{/literal} 
</head> 

<script type="text/javascript">
function goods_show(id){

<!--{literal}-->

art.dialog.open(url,{id:'select',title:'的:',width:760,height:380,padding: '10px'});

<!--{/literal}-->
  }
</script>

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

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

Statement:
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