How to use hbs - 10 common examples

To help you get started, we’ve selected a few hbs 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 davidmerfield / Blot / app / brochure / index.js View on Github external
var config = require("config");
var Express = require("express");
var brochure = new Express();
var hbs = require("hbs");
var Cache = require("express-disk-cache");
var cache = new Cache(config.cache_directory);
var warmCache = require('./warmCache');

// Configure the template engine for the brochure site
hbs.registerPartials(__dirname + "/views/partials");
brochure.set("views", __dirname + "/views");
brochure.set("view engine", "html");
brochure.engine("html", hbs.__express);

if (config.cache === false) {
  // During development we want views to reload as we edit
  brochure.disable("view cache");
} else {
  // This will store responses to disk for NGINX to serve
  brochure.use(cache);

  // Empty any existing responses
  cache.flush(config.host, function(err) {
    if (err) console.warn(err);
    warmCache(config.protocol + config.host, function(err){
      if (err) console.warn(err);
github engagementlab / CivicSeed / modules / middleware / hbs-helpers.js View on Github external
registerHelpers: function() {

		// console.log(hbs.compile);

		// hbs.compile

		hbs.registerHelper('extend', function(name, context) {
			var block = blocks[name];
			if(!block) {
				block = blocks[name] = [];
			}
			block.push(context(this));
		});

		hbs.registerHelper('block', function(name) {
			var val = (blocks[name] || []).join('\n');
			blocks[name] = [];
			return val;
		});

		hbs.registerHelper('admin', function(name, context) {

			return true;

		});

	},
github keeweb / keeweb / app / scripts / helpers / add.js View on Github external
const Handlebars = require('hbs');

// inspired by https://stackoverflow.com/questions/22103989/adding-offset-to-index-when-looping-through-items-in-handlebars/39588001#39588001
Handlebars.registerHelper('add', (lvalue, rvalue) => parseInt(lvalue) + parseInt(rvalue));
github mcguinness / saml-idp / app.js View on Github external
*/

  app.set('host', process.env.HOST || argv.host);
  app.set('port', process.env.PORT || argv.port);
  app.set('views', path.join(__dirname, 'views'));

  /**
   * View Engine
   */

  app.set('view engine', 'hbs');
  app.set('view options', { layout: 'layout' })
  app.engine('handlebars', hbs.__express);

  // Register Helpers
  hbs.registerHelper('extend', function(name, context) {
    var block = blocks[name];
    if (!block) {
      block = blocks[name] = [];
    }

    block.push(context.fn(this));
  });

  hbs.registerHelper('block', function(name) {
    const val = (blocks[name] || []).join('\n');
    // clear the block
    blocks[name] = [];
    return val;
  });
github konrad-g / ten / src / server / app / main / AppServerListener.ts View on Github external
public registerPage(page: any) {
    var viewsPath = path.join(page.getPath(), '/views');
    this.expressViews.push(viewsPath);
    this.express.set('views', this.expressViews);
    hbs.registerPartials(viewsPath);
    this.express.use('/stylesheets', express.static(path.join(page.getPath(), 'stylesheets')));
    this.express.use('/assets', express.static(path.join(page.getPath(), 'stylesheets')));

    if (this.USE_SCSS) {
      this.express.use(sassMiddleware({
        src: path.join(page.getPath(), 'stylesheets'),
        dest: path.join(page.getPath(), 'stylesheets'),
        indentedSyntax: false, // true = .sass and false = .scss
        sourceMap: true
      }));
    }
  }
github KnowledgeGarden / LiteWeight / app.js View on Github external
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var uuid = require('uuid');
var flash = require("connect-flash");
var session = require("express-session");

//environment
var environment = new require('./apps/environment')();

var app = express();
var hbs = require('hbs');

var viewPath = path.join(process.cwd(), "views");
app.set("view engine", "hbs");
app.set("views", viewPath); //path.join(__dirname, "/views"));
hbs.registerPartials(__dirname + '/views/partials');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

//app.use(cookieParser()); // collides with session
app.use(express.static(path.join(__dirname, "public")));
app.use(flash());

app.use(session({
  genid: function(req) {
    return uuid.v4(); // use UUIDs for session IDs
  },
github pillarjs / hbs / examples / partial / app.js View on Github external
// builtin
var fs = require('fs');

// 3rd party
var express = require('express');
var hbs = require('hbs');

var app = express();

hbs.registerPartial('partial', fs.readFileSync(__dirname + '/views/partial.hbs', 'utf8'));
hbs.registerPartials(__dirname + '/views/partials');

// set the view engine to use handlebars
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');

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

app.get('/', function(req, res) {

    res.locals = {
        some_value: 'foo bar',
        list: ['cat', 'dog']
    }

    res.render('index');
});
github MT-Libraries / MT-Notes / backend / app.js View on Github external
*/ 

    // extend
    hbs.localsAsTemplateData(app);
    hbs.registerHelper('extend', function (name, context) {
        var block = blocks[name];
        if (!block) {
            block = blocks[name] = [];
        }

        block.push(context.fn(this)); // for older versions of handlebars, use block.push(context(this));
    });

    // block
    var blocks = {};
    hbs.registerHelper('block', function (name) {
        var val = (blocks[name] || []).join('\n');

        // clear the block
        blocks[name] = [];
        return val;
    });

    // 模板引擎
    app.set('view engine', 'hbs');

    if (CONFIG.env.dev) {
        app.set('views', path.join(__dirname, '../frontend/src/tpl/dev'));
        hbs.registerPartials(path.join(__dirname, '../frontend/src/tpl/dev/tpl'));
    } else {
        app.set('views', path.join(__dirname, '../frontend/src/tpl/pro'));
        hbs.registerPartials(path.join(__dirname, '../frontend/src/tpl/pro/tpl'));
github mcguinness / saml-idp / app.js View on Github external
app.set('view engine', 'hbs');
  app.set('view options', { layout: 'layout' })
  app.engine('handlebars', hbs.__express);

  // Register Helpers
  hbs.registerHelper('extend', function(name, context) {
    var block = blocks[name];
    if (!block) {
      block = blocks[name] = [];
    }

    block.push(context.fn(this));
  });

  hbs.registerHelper('block', function(name) {
    const val = (blocks[name] || []).join('\n');
    // clear the block
    blocks[name] = [];
    return val;
  });


  hbs.registerHelper('select', function(selected, options) {
    return options.fn(this).replace(
      new RegExp(' value=\"' + selected + '\"'), '$& selected="selected"');
  });

  hbs.registerHelper('getProperty', function(attribute, context) {
    return context[attribute];
  });
github zmofei / dufing / middleware / dufing-hbs.js View on Github external
use(obj){
    //console.log(obj)
    //return;
    let self = this.proto;
    let _obj = obj || {};
    let viewPath = _obj.viewPath || '';
    let adminViewPath = _obj.adminViewPath || '';

    if(viewPath !=='')
    hbs.registerPartials(viewPath);//注册前台后台视图路径
    if(adminViewPath !== '')
    hbs.registerPartials(adminViewPath);//注册后台模版路径

    //console.log(_obj.exname)
    self.exname = _obj.exname || '.hbs'; //设置模版文件后缀
    //self.viewPath = viewPath;
    //self.adminViewPath = adminViewPath;
    return self
  };

hbs

Express.js template engine plugin for Handlebars

MIT
Latest version published 3 years ago

Package Health Score

40 / 100
Full package analysis