ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Use with SWAG #47

Closed ghost closed 10 years ago

ghost commented 10 years ago

Is it possible to use SWAG https://github.com/elving/swag with exphbs? And could you recommend a good implementation of it / example?

This is how I have started it, but I'm sure I'm missing something and would this conflict (using different modules)?

var exphbs  = require('express3-handlebars');
var hbs  = require('express3-handlebars').create();

//swag for handlebars 
var Handlebars = require('handlebars');
var Swag = require('swag');
Swag.registerHelpers(Handlebars);

Sorry for the noob question and hope ok to ask here.

ghost commented 10 years ago

Updated for errors in my 'fix'. I'll stop posting now! Actually think I figured it out. Created an instance (as per your README) and then did this:

var express = require('express');
var handlebars = require('handlebars');
var exphbs  = require('express3-handlebars');
var exphbspart = require('express3-handlebars').create();
var routes = require('./routes');
var http = require('http');
var path = require('path');

//swag for handlebars 
var Swag = require('swag');
Swag.registerHelpers(handlebars);

// EXPRESS
var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));

// Register `hbs.engine` with the Express app.
var hbs = exphbs.create({layoutsDir:'views/layouts/', partialsDir:'views/partials/', defaultLayout: 'main',     extname:'.handlebars'});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');

exphbspart.loadPartials(function (err, partials) {
    console.log(partials);
    // => { 'foo.bar': [Function],
    // =>    title: [Function] }
});

Once I read your source code and saw the way you have extended Handlebars and RTM, I got it to work for me (for now). Thanks and sorry for asking the dumb question!