Skip to content

Latest commit

 

History

History
137 lines (97 loc) · 2.84 KB

router.md

File metadata and controls

137 lines (97 loc) · 2.84 KB
title collection category
Router
docs
api

Overview

This document describes the various features, options and API router methods available on Templates.js.

Router methods

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 the load 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.

Methods

onLoad

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);
});

preLayout

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();
});

onLayout

Called after each [layout][] in a [layout-stack][] is applied.

app.onLayout(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

postLayout

Called after all [layouts][] have been applied to a view.

app.postLayout(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

onMerge

Called directly before [partials][] collections are merged onto the [context][].

app.onMerge(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

preCompile

Called before compiling a view.

app.preCompile(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

postCompile

Called after compiling a view.

app.postCompile(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

preRender

Called before rendering a view.

app.preRender(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

postRender

Called after rendering a view.

app.postRender(/\.hbs$/, function(view, next) {
  // do something with `view`
  next();
});

{%= reflinks(['express']) %}