How to use express-handlebars - 10 common examples

To help you get started, we’ve selected a few express-handlebars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gefangshuai / ANodeBlog / app.js View on Github external
));


passport.serializeUser(function (user, done) {
    done(null, user.id);
});

passport.deserializeUser(function (id, done) {
    done(null, id);
});

var app = express();
app.set('env', 'development');


var hbs = exphbs.create({
    partialsDir: 'views/partials',
    layoutsDir: "views/layouts/",
    defaultLayout: 'main',
    extname: '.hbs',
    helpers: hbsHelper
});

try {
    mongoose.connect(config.db.url);
} catch (error) {
    console.log(error);
}

// view engine setup
app.set('views', path.join(__dirname, 'views'));
github stoikerty / dev-toolkit / toolkit / documentation / example_files / server / bootstrap.js View on Github external
init(){
    // -> Set the folder for html views & disable powered-by header
    this.express.engine('html', hbs({ extname: 'html' }));
    this.express.set('views', process.cwd() + '/src/server/views');
    this.express.set('view engine', 'html');
    this.express.locals.settings['x-powered-by'] = false;
    this.express.disable('x-powered-by');
  }
github XeroAPI / xero-node / sample_app / index.js View on Github external
},
        debug: function(optionalValue) {
            console.log("Current Context");
            console.log("====================");
            console.log(this);

            if (optionalValue) {
                console.log("Value");
                console.log("====================");
                console.log(optionalValue);
            }
        }
    }
});

app.engine('handlebars', exphbs.engine);

app.set('view engine', 'handlebars');
app.set('views', __dirname + '/views');

app.use(express.logger());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: '123456' }));
app.use(express.static(__dirname + '/assets'));
// app.use(express.cookieSession({ secret: 'sfsdfsdfsdfsdf234234234fd', cookie: { maxAge: 123467654456 } }));

function authorizeRedirect(req, res, returnTo) {
    var xeroClient = getXeroClient(null, returnTo);
    xeroClient.getRequestToken(function(err, token, secret) {
        if (!err) {
            req.session.oauthRequestToken = token;
github stoikerty / dev-toolkit / src / templates / with-sass / src / server / index.js View on Github external
constructor() {
    // Let dev-toolkit know about express by setting `this.express`,
    // this allows dev-toolkit to attach the dev-server middleware to webpack
    this.express = express();

    // Handlebars is used for server-rendering the html template in `src/server/views`
    this.handlebarsInstance = expressHandlebars.create();

    // Use Handlebars as the view engine in express
    this.express.engine('hbs', this.handlebarsInstance.engine);
    this.express.set('views', serverViews).set('view engine', 'hbs');

    // Prevent express from sending powered-by header
    this.express.disable('x-powered-by');
  }
github shalomeir / snippod-boilerplate / snippod_webapp / server / config / express.js View on Github external
var expressConfig = function(app, express) {

  var hour = 3600000;
  var day = hour * 24;
  var week = day * 7;

  // Create `ExpressHandlebars` instance with a default layout.
  var hbs = exphbs.create({
    defaultLayout: 'main',
    layoutsDir: './server/templates/layouts/'
  });

  // Get current server environment
  var env = app.get('env');

  // Remove x-powered-by navbar (doesn't let clients know we are using Express)
  app.disable('x-powered-by');

  // Setup port for server to run on
  app.set('port', settings.server.port);

  // Setup path where all server templates will reside
  app.set('views', path.join(settings.root, 'server/templates'));
github enricolucia / pong / app.js View on Github external
for (var k in json) {
    if (json.hasOwnProperty(k)) {
      blockObj.data.root[k] = json[k];
    }
  }
  if (blockName in PARTIALS) {
    return PARTIALS[blockName](blockObj.data.root);
  }
  return blockObj.fn(blockObj.data.root);
};


// serve static files
app.use(express.static('public'));

tpl = exHb.create({
  defaultLayout: 'mainlayout',
  extname: '.hbs',
  layoutsDir: 'views/',
  partialsDir: 'views/',
  helpers: helpers
});

// set templates location
app.engine('.hbs', tpl.engine);
app.set('view engine', '.hbs');
app.set('views', __dirname + '/views/');


fetchJson = function(id) {
  var json;
  try {
github EthanRBrown / web-development-with-node-and-express / ch10 / meadowlark.js View on Github external
var express = require('express'),
	fortune = require('./lib/fortune.js'),
	formidable = require('formidable');

var app = express();

var credentials = require('./credentials.js');

// set up handlebars view engine
var handlebars = require('express-handlebars').create({
    defaultLayout:'main',
    helpers: {
        section: function(name, options){
            if(!this._sections) this._sections = {};
            this._sections[name] = options.fn(this);
            return null;
        }
    }
});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

app.set('port', process.env.PORT || 3000);

app.use(require('cookie-parser')(credentials.cookieSecret));
app.use(require('express-session')({
github SamsungInternet / podle / index.js View on Github external
// Set to true if you want to set all headers: Content-Security-Policy,
	// X-WebKit-CSP, and X-Content-Security-Policy.
	setAllHeaders: true,

	// Set to true if you want to disable CSP on Android where it can be buggy.
	disableAndroid: false,

	// Set to false if you want to disable any user-agent sniffing.
	// This may make the headers less compatible but it will be much faster.
	// This defaults to `true`. Should be false if behind cdn.
	browserSniff: false
}));

// Use Handlebars for templating
const hbs = exphbs.create({
	defaultLayout: 'v1',
	helpers: {
		ifEq: function(a, b, options) {
			return (a === b) ? options.fn(this) : options.inverse(this);
		},
		mangle: function(options) {
			return options.fn(this).replace(/[^a-z0-9]+/ig,'-');
		},
		bytesToMegabytes: function(options) {
			return (Number(options.fn(this)) / (1024 * 1024)).toFixed(2) + 'MB';
		},
		encodeURIComponent: function(options) {
			return encodeURIComponent(options.fn(this));
		}
	}
});
github ftlabs / screens / server / app.js View on Github external
const ftwebservice = require('express-ftwebservice');
const sentry = require('./sentry');
const app = express();

// The request handler must be the first item
app.use(sentry.requestHandler);

// The error handler must be before any other error middleware
app.use(sentry.errorHandler);

// Create Socket.io instance
app.io = require('socket.io')();
screens.setApp(app);

// Use Handlebars for templating
const hbs = exphbs.create({
	defaultLayout: 'main',
	helpers: {
		ifEq: function(a, b, options) { return (a === b) ? options.fn(this) : options.inverse(this); },
		join: function(arr) { return [].concat(arr).join(', '); },
		htmltitle: function(url) { return pages(url).getTitle() || url; },
		revEach: function(context, options) { return context.reduceRight(function(acc, item) { acc += options.fn(item); return acc; }, ''); },
		relTime: function(time) { return moment(time).fromNow(); },
		toLower: function(str) { return String(str).toLowerCase(); },
	}
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.hbs = hbs;

// Write HTTP request log using Morgan
app.use(morganLogger('dev'));
github EthanRBrown / web-development-with-node-and-express / ch07 / meadowlark.js View on Github external
var express = require('express');
var fortune = require('./lib/fortune.js');

var app = express();

// set up handlebars view engine
var handlebars = require('express-handlebars').create({
    defaultLayout:'main',
    helpers: {
        section: function(name, options){
            if(!this._sections) this._sections = {};
            this._sections[name] = options.fn(this);
            return null;
        }
    }
});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

app.set('port', process.env.PORT || 3000);

app.use(express.static(__dirname + '/public'));

express-handlebars

A Handlebars view engine for Express which doesn't suck.

BSD-3-Clause
Latest version published 3 months ago

Package Health Score

84 / 100
Full package analysis