自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

避免smarty與css語法沖突的方法

開發(fā) 前端
這篇文章主要介紹了避免smarty與css語法沖突的方法,實例分析了smarty與css中大括號{}沖突的處理技巧,需要的朋友可以參考下。

[[129020]]

本文實例講述了避免smarty與css語法沖突的方法。分享給大家供大家參考。具體分析如下:

熟悉css的人很快就會發(fā)現(xiàn)smarty和css的語法存在沖突,因為二者都需要使用大括號{}。如果簡單地將css標記嵌入到html文檔首部,將導致不可識別標記錯誤:

  1. <html> 
  2.  
  3. <head> 
  4.  
  5. <title>{$title}</title> 
  6.  
  7. <style type=text/css> 
  8.  
  9. p{ 
  10.  
  11. margin::2px 
  12.  
  13.  
  14. </style> 
  15.  
  16. </head> 
  17.  
  18. ... 

不要擔心,因為我們有3種解決方案。

一、使用link標記從另一個文件中提取樣式信息:

  1. <html> 
  2.  
  3. <head> 
  4.  
  5. <link rel=stylesheet type=text/css href=css/default.css/> 
  6.  
  7. </head> 
  8.  
  9. ... 

 

二、使用smarty的literal標記將樣式表信息包圍起來

這些標記告訴smarty不要解析該標記內(nèi)的任何內(nèi)容:

  1. <html> 
  2.  
  3. <head> 
  4.  
  5. {literal} 
  6.  
  7. p{ 
  8.  
  9. margin::2px 
  10.  
  11.  
  12. </style> 
  13.  
  14. {/literal} 
  15.  
  16. </head> 
  17.  
  18. ... 

 

三、修改smarty的默認定界符

可以通過設置center_delimiter和center_delimiter屬性來做到這一點:

  1. require(smarty.class.php); 
  2.  
  3. $smarty=newsmarty; 
  4.  
  5. $smarty->left_delimiter=''
  6.  
  7. $smarty->right_delimiter=''
  8.  
  9. ... 
  10.  
  11. ?> 

雖然3種解決方案都能解決問題,但其中***種可能是最方便的,因為將css放在單獨的文件中是一種常見的實踐做法。此外,這種解決方案不需要修改smarty的重要默認配置(定界符)。

希望本文所述對大家的php程序設計有所幫助。

責任編輯:王雪燕 來源: 站長網(wǎng)
相關推薦

2010-09-08 15:49:21

SmartyCSS

2023-05-25 08:39:05

前端CSS

2020-10-19 15:20:51

Ansible系統(tǒng)運維

2009-01-20 10:51:00

局域網(wǎng)IP地址分配

2010-09-06 13:15:48

CSS定位

2010-09-06 13:59:23

CSS縮寫

2010-08-25 09:30:56

marginCSS

2020-07-14 13:16:32

JavaScript解構(gòu)對象

2023-08-23 10:19:25

數(shù)據(jù)MySQL

2023-11-13 18:22:14

Docker開發(fā)

2025-03-18 14:27:35

2010-09-14 16:04:40

CSSclip屬性

2023-07-06 07:55:15

Redis內(nèi)存數(shù)據(jù)庫

2010-09-03 13:23:07

absoluterelativeCSS

2010-01-05 17:02:47

Debian系統(tǒng)

2023-01-27 09:14:35

CSS原生嵌套

2009-07-15 09:58:51

IbatisN+1查詢

2010-09-14 16:57:29

DIV絕對定位CSS

2010-09-16 11:31:17

CSS Hack

2010-08-27 09:29:40

CSSbehavior
點贊
收藏

51CTO技術棧公眾號