Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
use el ayudante de handlebars-express en una vista

Estoy usando nodejs como backend y la biblioteca handlebars-express

Tengo 3 archivos, mi index.js, loginController.js y loginTemplate.handlebars

En mi index.js he declarado manillares como este

 const handlebarsInstance = require('./src/services/handlebarsService'); var hbs = handlebarsInstance.handlebars; const server = express(); server.engine('handlebars', hbs.engine); server.set('view engine', 'handlebars');

En mi loginController tengo esto

 const handlebarsInstance = require('../services/handlebarsService'); handlebarsInstance .getTemplate('loginController/loginTemplate', data) .then((loginCompiledTemplate) => { res.send(loginCompiledTemplate); });

Mi servicio de manillares:

 const handlebars = require('express-handlebars').create({ helpers: { ifCond: function (v1, operator, v2, options) { switch (operator) { case '==': return v1 == v2 ? true : false; case '===': return v1 === v2 ? true : false; case '!=': return v1 != v2 ? true : false; case '!==': return v1 !== v2 ? true : false; case '<': return v1 < v2 ? true : false; case '<=': return v1 <= v2 ? true : false; case '>': return v1 > v2 ? true : false; case '>=': return v1 >= v2 ? true : false; case '&&': return v1 && v2 ? true : false; case '||': return v1 || v2 ? true : false; default: return false; } }, }, layoutsDir: __dirname + '/src/views', }); const getTemplate = async (path, data) => { const template = await handlebars .getTemplate(`./src/views/${path}.handlebars`) .catch((err) => { console.log(err); }); return template(data); }; module.exports = { getTemplate, handlebars };

Pero cuando en mi vista trato de llamar a "ifCond" no lo reconoce, porque me da este error

 {{#if campos }} {{#each camposManuales}} {{#ifCond this.field_type == 1 }} a {{/ifCond}} {{/each}} {{/if}}

El error:

 UnhandledPromiseRejectionWarning: Error: Parse error on line 14: .field_type == 1 }}

¿Cómo puedo arreglar esto? ¿Qué está mal? ¡¡Muchas gracias!! ^^

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!