How to use jade

Comprehensive jade code examples:

How to use jade.compileFileClient:

109
110
111
112
113
114
115
116
117
118

var fs   = require('fs');
var jade = require('jade');

// Compile the template to a function string
var jsFunctionString = jade.compileFileClient('/path/to/jadeFile.jade', {name: "fancyTemplateFun"});

// Maybe you want to compile all of your templates to a templates.js file and serve it to the client
fs.writeFileSync("templates.js", jsFunctionString);
Here's what the output function string looks like (written to templates.js).

How to use jade.renderFile:

174
175
176
177
178
179
180
An options object (see above), also used as the locals object
returnsstring
The resulting html string
var jade = require('jade');

var html = jade.renderFile('path/to/file.jade', options);
// ...

How to use jade.render:

163
164
165
166
167
168
169
170
171
172
An options object (see above), also used as the locals object
returnsstring
The resulting html string
var jade = require('jade');

var html = jade.render('string of jade', options);
// => '<string>of jade</string>'
jade.renderFile(filename, options)
filenamestring
The path to the jade file to render

How to use jade.compileFile:

57
58
59
60
61
62
63
64
65
66
returnsfunction
A function to generate the html from an object containing locals
var jade = require('jade');

// Compile a function
var fn = jade.compileFile('path to jade file', options);

// Render the function
var html = fn(locals);
// => '<string>of jade</string>'

How to use jade.compileClient:

74
75
76
77
78
79
80
81
82
83
returnsstring
A string of JavaScript representing a function
var jade = require('jade');

// Compile a function
var fn = jade.compileClient('string of jade', options);

// Render the function
var html = fn(locals);
// => 'function template(locals) { return "<string>of jade</string>"; }'

How to use jade.compileClientWithDependenciesTracked:

19
20
21
22
23
24
25
26
27
28

options.filename = fileName;

var result;
try {
    result = jade.compileClientWithDependenciesTracked(inputString, options);
} catch (e) {
    self.emit("error", e);
    return;
}

How to use jade.compile:

40
41
42
43
44
45
46
47
48
49
returnsfunction
A function to generate the html from an object containing locals
var jade = require('jade');

// Compile a function
var fn = jade.compile('string of jade', options);

// Render the function
var html = fn(locals);
// => '<string>of jade</string>'