Pug渲染模板
pug模板語法
- pug渲染模板語法
- 1屬性
- 2插入代碼
- 3條件分支
- 3文檔頭申明
- 4文檔內容包含
- 迭代
pug渲染模板語法
pug標簽屬性和html類似,因此說明pug語法的時候會和html進行對比
1屬性
用法標簽名(屬性名=屬性值)
多行屬性之間可以用逗號和空格隔開
等效與
<a href="baidu.com"></a> <div style="color:#ffffff">2插入代碼
使用‘-’開始一段不直接輸出的代碼
- for(var x=0;x<3;x++)li item等效于
<li>item</li> <li>item</li> <li>item</li>3條件分支
case和switch
- var friends=0 case friendwhen 0p 沒有朋友等效于
<p>你沒有朋友</p>3文檔頭申明
doctype html等效與
<!DOCTYPE html>4文檔內容包含
使用include 將外部pug文檔內容引入
比如index.pug文件內容如下
注意pug中每個標簽左對齊表示在同一等級,前面多出一個空格就會被上一個標簽自動渲染為內部標簽
head.pug內容
headscript(src='./image')最終渲染成為html
<!DOCTYPE html> <html><head><script src='./image'></script></head> <body><h1>第一個網站</h1> </body> </html>迭代
ul each val in [1,2,3,4,5]li=val等效與
<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li> </ul>參考資料
pug中文文檔
總結
- 上一篇: 2010年度 中国WEB应用防火墙厂家和
- 下一篇: Win10下WinRAR“拒绝访问”解决