title | collection | category |
---|---|---|
Router |
docs |
api |
This document describes the various features, options and API router methods available on Templates.js.
Router methods are similar to the router METHODS in [express][], but instead of representing HTTP METHODS, the router methods here represent significant points or "stages" during the build cycle.
Summary
onLoad
: Immediately after a view is loaded, after theload
event is emitted, and before adding the view to a collection.preLayout
: Immediately before the first [layout][] in a [layout-stack][] is applied to a view.onLayout
: Called after each [layout][] in a [layout-stack][] is applied.postLayout
: Called after all [layouts][] have been applied to a view.onMerge
: Called directly before [partials][] collections are merged onto the [context][].preCompile
: Called before compiling a view.postCompile
: Called after compiling a view.preRender
: Called before rendering a view.postRender
: Called after rendering a view.
Immediately after a view is loaded, as a last step just before adding the view to a collection.
Example
Parse YAML Front Matter and add the parsed data object to view.data
:
var matter = require('parser-front-matter');
app.onLoad(/\.hbs$/, function(view, next) {
matter.parse(view, next);
});
Immediately before the first [layout][] in a [layout-stack][] is applied to a view.
app.preLayout(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called after each [layout][] in a [layout-stack][] is applied.
app.onLayout(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called after all [layouts][] have been applied to a view.
app.postLayout(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called directly before [partials][] collections are merged onto the [context][].
app.onMerge(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called before compiling a view.
app.preCompile(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called after compiling a view.
app.postCompile(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called before rendering a view.
app.preRender(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
Called after rendering a view.
app.postRender(/\.hbs$/, function(view, next) {
// do something with `view`
next();
});
{%= reflinks(['express']) %}