Moe-js v0.3

Express Integration

You can use Moe-js as a view engine in Express:

const moe = require('@toptensoftware/moe-js');

// Use moe-js for '.moe' view templates

// Where to look for views
app.set('views', path.join(__dirname, 'views'));

// Default view engine to use when render call doesn't include file extension
app.set('view engine', 'moe');

Moe-js's Express middleware compiles view templates as async templates, so you can use await in your views!


When using Moe-js with Express, you can specify an outer layout file into which the internal view is wrapped.

The name of the layout is determined in the following way:

  1. The model.layout property
  2. The app.locals.layout property
  3. Defaults to "layout"

To suppress the use of a layout set the property to false. Layout files are searched for in the same directory as other views.

On rendering the layout, the inner view's rendered body is available as the special property inner.body:

A simple minimal layout might look like this:

{{{ inner.body }}}

Subscribe for more like this. No spam, just fun tech stuff :)

Or, find me on Twitter: @toptensoftware.