How to use the express-handlebars.create function in express-handlebars

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 / 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'));
github abecms / abecms / src / server / app.js View on Github external
middleIsAuthorized,
  middleLiveReload
} from './middlewares'

import getHome from './routes/get-home'

require('events').EventEmitter.defaultMaxListeners = 100

var abePort = null

if (config.port) abePort = config.port
if (process.env.PORT) abePort = process.env.PORT

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'

var html = exphbs.create({
  extname: `.${config.files.templates.extension}`,
  helpers: {
    abe: compileAbe,
    listPage: listPage,
    math: math,
    printInput: printInput,
    abeImport: abeImport,
    moduloIf: moduloIf,
    testObj: testObj,
    notEmpty: notEmpty,
    printJson: printJson,
    className: className,
    attrAbe: attrAbe,
    folders: folders,
    printConfig: printConfig,
    ifIn: ifIn,
github shorttompkins / movieq / server / configure.js View on Github external
module.exports = function(app) {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'handlebars');

    app.engine('handlebars', exphbs.create({
        defaultLayout: 'main',
        layoutsDir: app.get('views') + '/layouts'
    }).engine);

    app.use(morgan('dev'));
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(bodyParser.json());
    app.use(methodOverride());
    app.use(cookieParser('super-secret-key-here'));
    app.use(session({
        secret: 'super-secret-key-here',
        saveUninitialized: true,
        resave: true
    }));

    app.use('/public/', express['static'](path.join(__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