Skip to content

Request: View configuration to autoload helepers #846

@Iheartweb

Description

@Iheartweb

Helpers like partials are a nearly ubiquitous concept among tempting engines. Just like partials it would be nice to be able to express a path in the view config:

views: {
  engines: { html: 'handlebars' },
  path: __dirname + '/templates',
  partialsPath: __dirname + '/templates/withPartials',
  helpersPath: __dirname + '/templates/helpers'
} 

Currently I achieve the desired functionality by:

var Hapi = require('hapi'),
  handlebars = require('handlebars'),
  loader = require('node-glob-loader');

// Load View Helpers
loader.load('./application/views/helpers/*.js', function (exports) {
  exports(handlebars);
});

With the config: views.engine.module = handelbars.

And the helpers following the form:

module.exports = function (handlebars) {
  handlebars.registerHelper('foo', function () {
    return 'bar';
  });
};

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions