Tag: handlebars.js

鲍尔安装,但给每个命令的错误

我已经通过npm npm install -g bower ,我没有问题。 但是当我想运行凉亭,即使只是bower或bower -help我得到以下错误: module.js:340 throw err; ^ Error: Cannot find module './parser' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/usr/local/lib/node_modules/bower/node_modules/handlebars/lib/handlebars/compiler/base.js:1:80) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) 似乎无法在网上find任何与此问题的人。

无法使用Node的Express访问Handlebars模板中的对象属性

我在Express框架下使用Handlebars的hbs模块: var hbs = require('hbs'); app.set('view engine', 'html'); app.engine('html', hbs.__express); 像这样设置我的视图variables: userModel.find({ twitter: username }, function(err, profile){ if(err){ return next(err); } res.render('profile.html', { profile: profile }); }); 如果我在模板中这样做: {{profile}} 我得到: { name: 'xxxxx', twitter: 'xxxxx', avatar: 'xxxxxxxx', _id: 531cd64568282e0000000001, __v: 0, links: [], booked: [] } 但是,如果我做一些简单的事情: <p class="profile-name">{{profile.name}}</p> 在同一个文件中,没有输出! 有任何想法吗?

将Flash消息暴露给Handlebars模板

我正在构buildSPA:Backbone.js,Node.js,Mongo。 我使用Passport.js进行身份validation,并想知道如何将req.flashvariables暴露给我的Handlebars模板? 在这种情况下,如果用户试图用电子邮件login,我想在我的视图中公开flashvariables“signupMessage”。 在我的Express服务器上: app.use(function(req, res, next){ res.locals.flash = req.flash next(); }); 护照本地策略: passport.use('local-signup', new LocalStrategy({ usernameField : 'email', passwordField : 'password', petnameField : 'petname', passReqToCallback : true // allows us to pass back the entire request to the callback }, function(req, email, password, done) { process.nextTick(function() { User.findOne({ 'local.email' : email }, function(err, user) […]

Koa-handlebars:无法渲染视图:无法find部分

// project/layouts/main.hbs <!DOCTYPE html> <html lang="en"> <head> </head> <body> {{{@body}}} </body> </html> // project/views/home-public.hbs {{> nav-public}} <div class="container"> <div class="starter-template"> <h1>Home Public</h1> <p class="lead">This is my home.</p> </div> </div> // project/partials/nav-public.hbs <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> […]

在Ember.js中预编译模板

我正在创build一个带有Node后端的Ember项目,并希望将我的模板作为单独的文件,而不是将它们内联在index.html文件中。 我已经阅读了很多文章解释这一点,但是我仍然无法把头脑包裹在整个过程中,以及index.html文件等等什么时候完成。 咕噜是最有效的做这样的事情? 这是我的grunt文件的样子。 Gruntfile.js: grunt.loadNpmTasks('grunt-ember-templates'); grunt.registerTask('build', ['emberTemplates', 'concat', 'uglify']); //pass the compiled templates into your concat and uglify tasks. Don't worry, they don't care if they are mushed altogether // with the following task in the Grunt.config emberTemplates: { compileComponents: { options: { templateBasePath: /templates\// }, files: { 'build/precompile/components.js': 'templates/components/*.hbs' } }, compileRoutes: { […]

如何包含一个车把js文件到另一个?

我是新手柄诱人与Nodejs。 我想包括2个车把文件到一个。 所以经过一些Googlesearch,我尝试了这个 layout.hbs <!DOCTYPE html> <html> <head> <title>{{title}}</title> <link rel='stylesheet' href='/stylesheets/bootstrap.css' /> <link rel='stylesheet' href='/stylesheets/base.css' /> </head> <body> {{> header}} {{{body}}} {{> footer}} </body> </html> heaeder.hbs <p>I am header</p> footer.hbs <p>I am footer</p> 和我的文件夹结构是 views – layout.hbs – header.hbs – footer.hbs 但是这不起作用,我得到这个错误 Error at Object.<anonymous> (C:\SVN HOME 2\YASSER\One-Bitbucket\node_modules\hbs\node_modules\handlebars\dist\cjs\handlebars\exception.js:29:23) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) […]

我怎样才能在集合的另一个集合中的父级以外使用集合列表?

试图在另一个目录中使用集合certificate是困难的。 主要collections目录:/src/templates/roles/one.hbs等等 然后在我的主页dir:/src/templates/pages/roles.hbs 我想在上面的模板中使用一个集合列表,但它不工作。 以下是我所尝试的: {{#each pages}} {{title}} {{/each}} 这可以在angular色页面内部工作,但不在页面内部或页面内/我的/ templates / pages /文件夹中 Gruntfile.js assemble: { options: { helpers: ['handlebars-helper-slugify', '<%= config.src %>/helpers/slugify.js'], data: '*.json', // Set the "default" assets dir at the task-level imageAssets: '<%= config.base %>assets/img', collections: [ { name: 'navMain', sortby: 'number', sortorder: 'ascending' }, { name: 'newsMain', sortby: 'postedon', sortorder: […]

在具有自定义键/值的Mongoose / Handlebars中创build一个Schema对象

我想创build一个表单来inputmongo / mongoose模式中的对象的自定义键和值,以最终在句柄视图中看到。 看例子更好的解释。 任何帮助将是伟大的。 🙂 mongoose/ Mongodb模式: var docketSchema = new Schema({ staff: [{ String: String, String: String }] }); 把手input视图: <div class="form-group"> <input value="{{input.staffkey1}}"> <input value="{{input.staffvalue1}}"> </div> <div class="form-group"> <input value="{{input.staffkey2}}"> <input value="{{input.staffvalue2}}"> </div>

使用i18n与hbs和express

我试图用hbs正确使用i18n,但还没有成功。 这是我的server.js代码: var express = require('express'); var server = express(); var hbs = require('hbs'); var i18n = require('i18n'); var cookieParser = require('cookie-parser'); i18n.configure({ locales: ['en', 'fr'], cookie: 'locale', directory: __dirname + "/locales" }); hbs.registerPartials(__dirname + '/views'); server.set('view engine', 'hbs'); server.engine('hbs', hbs.__express); server.use(cookieParser()); server.use(i18n.init); hbs.registerHelper('__', function () { return i18n.__.apply(this, arguments); }); hbs.registerHelper('__n', function () { […]

无法在使用把手的mandrill模板中显示javascript对象属性

我正在尝试通过在节点项目中使用mandrill模板API来显示dynamic内容。 我已经跟随了文档,看了很多例子,并且大部分可以使事情工作。 但是,当我尝试访问通过在mandrill模板中的api传递的对象的属性时,它不显示任何内容。 这是我的mandrill模板(使用车把): <p>{{greeting}} {{person.firstName}},</p> <p>{{greeting}} {{person.0.firstName}},</p> <p>Your location is {{person.location}}.</p> 现在,问候语显示在global_merge_vars部分中传递的值。 但是person对象的属性并不显示,就好像它们是未定义的一样。 这里是被发送的JSON的一部分: var greeting = "Hello "; var person = {firstName:"testfname",location:"testlocation"}; var globalMergeVars = [ {"name": "greeting","content":greeting}, {"name": "person","content": person}, ]; 我没有正确地传递对象或在api调用中正确命名'name'属性? 我尝试了一堆不同的东西。 我知道我可以在globalMergeVars对象中创build多个variables,而不是传递整个人物对象,但是我有更多的属性附加到person对象。 我也成功地使用了一个项目数组的每个循环,所有得到正确显示。 谢谢。