Plain Text jade提供了3种得到纯文本的方法. Piped Text 添加纯文本的一个最简单的方法就是在文本最前面加|符号即可. jade: p | It must always be on its own <strong>line</strong> Inline in a Tag 还有一种简单的方法:内嵌在一个标签后即可. jade: p Plain text can include <strong>html</strong> Block in…
nodejs+express经常会看到使用jade视图引擎,但是有些人想要访问普通的html页面,这也是可以的: var express = require('express'); var port = process.env.port||3000; var app = new express(); app.set('views','./views'); app.set('view engine','jade'); app.use(express.static('./public')); app…
Mixin mixin允许我们对某一个块的重复使用,类似于函数. 用法:首先声明mixin,然后使用(在mixin名字之前加+即可以使用)即可. 最简单的mixin jade: //- 声明 mixin list ul li foo li bar li baz //- 使用 +list +list html: <ul> <li>foo</li> <li>bar</li> <li>baz</li> </ul> &…
Template inheritance jade支持通过关键字block和extends来实现模板继承. 比如,在layout.jade写上如下代码 html head title My Site - #{title} block scripts script(src='/jquery.js') body block content p Nothing block foot #footer p some footer content 中间的block content代表块,content表示块…
Includes jade允许利用include将其他文件(支持filters所支持的类型)中的代码嵌入当前代码中. jade: //- index.jade doctype html html include ./includes/head.jade body h1 My Site p Welcome to my super lame site. include ./includes/foot.jade //- includes/head.jade head title My Site scr…
Filters jade允许将其他语言嵌套到jade语言之中. 支持的有:coffee-script,:babel,:uglify-js, :less,:markdown-it. jade: :markdown # Markdown I often like including markdown documents. script :coffee-script console.log 'This is coffee script' html: <h1>Markdown</h1> &…
Extends jade允许多个jade文件继承一个jade文件. jade: //- layout.jade doctype html html head block title title Default title body block content //- index.jade extends ./layout.jade block title title Article Title block content h1 My Article html: 生成的index.html中 <!…
Case jade中的case类似js中的switch语句. 当前一个when中无语句的时候,将一直往下直至遇到一个有语句的when才跳出. jade: - var friends = 10 case friends when -1 //- 执行when 1中的语句 when 0 p you have no friends when 1 p you have a friend default p you have #{friends} friends html: <p>you have 10…