Skip to content
Mark Birbeck edited this page Sep 7, 2016 · 3 revisions

The adapter wraps template modules with a standard interface:

  • renderFile()
  • render()

renderFile

If a template engine supports a method called __express() then it is used to provide the renderFile() method. If __express() does not exist, but renderFile() does, then this is used instead.

If neither method exists then a renderFile() method is created that will load the template referred to in the path parameter and then call render().

render

If a templating engines supports render() then the render() adapter method simply points to the engine's method. If the method is synchronous -- i.e., there is no callback parameter -- then a flag can be set in the configuration options so that the adapter will place the render() function into an asynchronous wrapper. For example, the Haml template engine has a synchronous render() method, so the following setting is required:

haml: {
  "sync": true
}

If the engine does not provide a render() method then one is created which carries out the following steps:

  • newContext() is called on the engine to create a new context;
  • any provided local variables are added to this context;
  • compile() is called on the engine to compile a template and create a template function;
  • the template function is called using the context.

Clone this wiki locally