PHP常規模板引擎中與CSS/JSON衝突的解決

來源:互聯網
上載者:User

標籤:style   blog   http   io   使用   java   ar   strong   sp   

主要針對對象:Smarty/Dwoo

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

其實以前都不怎麼關注模板引擎,覺得沒必要使用。但隨著年齡的增加,代碼潔癖越來越嚴重,才開始碰到這個問題。

 

Smarty和CSS/JS的文法存在衝突,因為二者都需要使用大括弧{}。雖然可以改Smarty的界定符,但你在一個現存系統中,去修改所有相關代碼,是不划算的。

 

1. 避免同時出現

通過外部參考的方式避免。問題是避無所避。所以這種情況只適合少量簡單的情況。

 

2. 修改Smarty界定符

 

2. 使用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>

PHP常規模板引擎中與CSS/JSON衝突的解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.