express-bem / bh

bh.js engine for express-bem
https://github.com/express-bem/express-bem
MIT License
1 stars 2 forks source link

How to specify a template file extension? #1

Closed remnev closed 9 years ago

remnev commented 9 years ago

Hi!

For example, I have two separately kinds of templates. There are the server-side templates demo.server.bh.js and the client-side demo.browser.bh.js. How to specify any custom file extension (server.bh.js in this case) to the render processor?

My test example:

var express = require('express');
var app = express();
var ExpressBem = require('express-bem');
var bem = ExpressBem({
        root: '.',
        path: './bundles'
    }).bindTo(app);

bem.usePlugin('express-bem-bh');

app.get('/', function (req, res) {
    res.render('demo', {bemjson: {block: 'root'}});
});

app.listen(3000);
qfox commented 9 years ago

@remnev At first you can pass full path 'demo.server.bh.js' or 'demo.server'

Also you can use engine with another extension:

bem.engine('.server.bh.js', require('express-bem-bh/lib/engines/bh'));

or do a trick:

bem.engine('.server.bh.js', function (name, options, cb) {
    this.thru('bh');
});
bem.usePlugin('express-bem-bh');

p.s. You can see all possible engine declaration cases in readme: https://github.com/express-bem/express-bem#engine

Thanks for the question ;-)

remnev commented 9 years ago

Nice! I enjoyed this:

expressBem.bindTo(app);
expressBem.engine('.server.bh.js', require('express-bem-bh/lib/engines/bh'));