ericf / express-handlebars

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

Support for declarative templates in view? #84

Closed ghost closed 9 years ago

ghost commented 9 years ago

server.js includes the following...

// view engine setup
var hbs         = require('express-handlebars');
app.engine('handlebars', hbs( {
    layoutsDir: __dirname + '/app/views/layouts',
    partialsDir: __dirname + '/app/views/partials',
    defaultLayout: 'default'
}));
app.set('view engine', 'handlebars');
app.set('views', __dirname + '/app/views');

views/test.handlebars includes

{{!< notDefault }}
<h1>Not the default</h1>

views/templates includes two templates; default.handlebars and notDefault.handlebars.

When test is rendered, it always uses the default template unless I pass the template in during render via

res.render('test', {layout: 'notDefault'});

This works as expected. Am I missing something or is this not currently supported? I am using express-hbs v1.1.0 and express 4.

Thanks

ericf commented 9 years ago

What is {{!< notDefault }}? I haven't seen this Handlebars syntax before.

ghost commented 9 years ago

Ghost and express-hbs each use that syntax to extend Handlebars templates. http://docs.ghost.org/themes/structure/#partials- https://github.com/barc/express-hbs#layouts

I thought it was a standard handlebars feature, but after searching the Handlebars docs, I think perhaps not?

Sorry for the confusion.

ericf commented 9 years ago

So what exactly are you trying to accomplish here? They might be another way I can help.

ghost commented 9 years ago

I appreciate the offer, but that won't be necessary. Once I realized it wasn't part of the spec I restructured my templates to achieve what I wanted. We are considering using express-handlebars to customize an angular web app prior to delivery. Seems to work well. Thanks.