index.js
function (view, locals, cb) {
    if (typeof locals === 'function') {
      cb = locals;
      locals = {};
    }

    // if `view` is a function, it's probably from chaining
    // a collection method
    if (typeof view === 'function') {
      return view.call(this);
    }

    // if `view` is a string, see if it's a cache view
    if (typeof view === 'string') {
      view = this.lookup(view);
    }

    locals = locals || {};

    // add `locals` to `view.contexts`
    view.ctx('render', locals);
    var data = this.cache.data;
    for (var key in locals) {
      if (locals.hasOwnProperty(key) && !data.hasOwnProperty(key)) {
        data[key] = locals[key];
      }
    }

    // handle `preRender` middleware
    this.handleView('preRender', view, locals);

    // build the context for the view
    var ctx = this.context(locals);

    // get the engine
    var engine = this.engine(locals.engine ? locals.engine : view.engine);

    if (typeof cb !== 'function') {
      throw this.error('render', 'callback');
    }
    if (typeof engine === 'undefined') {
      throw this.error('render', 'engine', path.extname(view.path));
    }
    if (!engine.hasOwnProperty('render')) {
      throw this.error('render', 'method', JSON.stringify(view));
    }

    // if it's not already compiled, do that first
    if (typeof view.fn !== 'function') {
      try {
        var isAsync = typeof cb === 'function';
        view = this.compile(view, locals, isAsync);
        return this.render(view, locals, cb);
      } catch (err) {
        this.emit('error', err);
        return cb.call(this, err);
      }
    }

    var context = this.context(view, ctx, locals);

    // render the view
    return engine.render(view.fn, context, function (err, res) {
      if (err) {
        this.emit('error', err);
        return cb.call(this, err);
      }
      // handle `postRender` middleware
      view.content = res;
      this.handle('postRender', view, locals, cb);
    }.bind(this));
  }
function (view, locals, cb) {
    if (typeof locals === 'function') {
      cb = locals;
      locals = {};
    }

    // if `view` is a function, it's probably from chaining
    // a collection method
    if (typeof view === 'function') {
      return view.call(this);
    }

    // if `view` is a string, see if it's a cache view
    if (typeof view === 'string') {
      view = this.lookup(view);
    }

    locals = locals || {};

    // add `locals` to `view.contexts`
    view.ctx('render', locals);
    var data = this.cache.data;
    for (var key in locals) {
      if (locals.hasOwnProperty(key) && !data.hasOwnProperty(key)) {
        data[key] = locals[key];
      }
    }

    // handle `preRender` middleware
    this.handleView('preRender', view, locals);

    // build the context for the view
    var ctx = this.context(locals);

    // get the engine
    var engine = this.engine(locals.engine ? locals.engine : view.engine);

    if (typeof cb !== 'function') {
      throw this.error('render', 'callback');
    }
    if (typeof engine === 'undefined') {
      throw this.error('render', 'engine', path.extname(view.path));
    }
    if (!engine.hasOwnProperty('render')) {
      throw this.error('render', 'method', JSON.stringify(view));
    }

    // if it's not already compiled, do that first
    if (typeof view.fn !== 'function') {
      try {
        var isAsync = typeof cb === 'function';
        view = this.compile(view, locals, isAsync);
        return this.render(view, locals, cb);
      } catch (err) {
        this.emit('error', err);
        return cb.call(this, err);
      }
    }

    var context = this.context(view, ctx, locals);

    // render the view
    return engine.render(view.fn, context, function (err, res) {
      if (err) {
        this.emit('error', err);
        return cb.call(this, err);
      }
      // handle `postRender` middleware
      view.content = res;
      this.handle('postRender', view, locals, cb);
    }.bind(this));
  }
function ( view , locals , cb ) { if ( typeof locals === 'function' ) { cb = locals ; locals = { } ; } // if `view` is a function, it's probably from chaining // a collection method if ( typeof view === 'function' ) { return view . call ( this ) ; } // if `view` is a string, see if it's a cache view if ( typeof view === 'string' ) { view = this . lookup ( view ) ; } locals = locals || { } ; // add `locals` to `view.contexts` view . ctx ( 'render' , locals ) ; var data = this . cache . data ; for ( var key in locals ) { if ( locals . hasOwnProperty ( key ) && ! data . hasOwnProperty ( key ) ) { data [ key ] = locals [ key ] ; } } // handle `preRender` middleware this . handleView ( 'preRender' , view , locals ) ; // build the context for the view var ctx = this . context ( locals ) ; // get the engine var engine = this . engine ( locals . engine ? locals . engine : view . engine ) ; if ( typeof cb !== 'function' ) { throw this . error ( 'render' , 'callback' ) ; } if ( typeof engine === 'undefined' ) { throw this . error ( 'render' , 'engine' , path . extname ( view . path ) ) ; } if ( ! engine . hasOwnProperty ( 'render' ) ) { throw this . error ( 'render' , 'method' , JSON . stringify ( view ) ) ; } // if it's not already compiled, do that first if ( typeof view . fn !== 'function' ) { try { var isAsync = typeof cb === 'function' ; view = this . compile ( view , locals , isAsync ) ; return this . render ( view , locals , cb ) ; } catch ( err ) { this . emit ( 'error' , err ) ; return cb . call ( this , err ) ; } } var context = this . context ( view , ctx , locals ) ; // render the view return engine . render ( view . fn , context , function ( err , res ) { if ( err ) { this . emit ( 'error' , err ) ; return cb . call ( this , err ) ; } // handle `postRender` middleware view . content = res ; this . handle ( 'postRender' , view , locals , cb ) ; } . bind ( this ) ) ; }
Render `content` with the given `locals` and `callback`.

```js
var blogPost = app.post('2015-09-01-foo-bar');
app.render(blogPost, function(err, view) {
// `view` is an object with a rendered `content` property
});
```

@name .render
@param  {Object|String} `file` String or normalized template object.
@param  {Object} `locals` Locals to pass to registered view engines.
@param  {Function} `callback`
@api public
Render content with the given locals and callback .