How to use pug

Comprehensive pug code examples:

How to use pug.compileFileClient:

197
198
199
200
201
202
203
204
205
206
```js
var fs = require('fs');
var pug = require('pug');

// Compile the template to a function string
var jsFunctionString = pug.compileFileClient('/path/to/pugFile.pug', {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);
```

How to use pug.render:

246
247
248
249
250
251
252
253
254
255
    </script>
  </body>
</html>
```

### pug.render(source, ?options, ?callback)

```parameter-list
source
~ string

How to use pug.compileClientWithDependenciesTracked:

148
149
150
151
152
153
154
155
156
157
// Render the function
var html = fn(locals);
// => 'function template(locals) { return "<string>of pug</string>"; }'
```

### pug.compileClientWithDependenciesTracked(source, ?options)

Same as <code>[compileClient]</code> except that this method returns an object of the form:

```js

How to use pug.compileClient:

118
119
120
121
122
123
124
125
126
127
// Render the function
var html = fn(locals);
// => '<string>of pug</string>'
```

### pug.compileClient(source, ?options)

Compile a Pug template to a string of JavaScript, which can be used client side.

```parameter-list

How to use pug.compile:

58
59
60
61
62
63
64
65
66
67
~ The name of the template function. Only applies to `compileClient` functions. Defaults to `'template'`.
```

## Methods

### pug.compile(source, ?options)

Compile a Pug template to a function, which can be rendered multiple times with different locals.

```parameter-list

How to use pug.__express:

169
170
171
172
173
174
175
176
177
178
179
180
expressApp.set('views', path.join(__dirname, 'views'));


// ref: https://blog.stigok.com/post/disable-pug-debug-output-with-expressjs-web-app
expressApp.engine('pug', (path, options, fn) => {
	options.debug = false;
	return pug.__express.call(null, path, options, fn);
});


expressApp.set('view engine', 'pug');

How to use pug.renderFile:

296
297
298
299
300
301
302
303
304
305
```

```js
var pug = require('pug');

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

## Properties

How to use pug.compileFile:

88
89
90
91
92
93
94
95
96
97
// Render the function
var html = fn(locals);
// => '<string>of pug</string>'
```

### pug.compileFile(path, ?options)

Compile a Pug template from a file to a function, which can be rendered multiple times with different locals.

```parameter-list