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

116
Views
Problema con los ayudantes de la sección del manillar express

No puedo hacer que el asistente de sección funcione según lo previsto. El cuerpo de login.hbs se analizó normalmente, pero la sección js nunca se analizó. Intenté usar ayudantes dentro res.render() y puse la section() directamente en engine() y tampoco funcionó

aplicación.js

 import express from "express" import expressHbs from "express-handlebars" const app = express(); app.use(express.urlencoded({ extended:true })); app.engine('hbs', expressHbs.engine({ defaultLayout: 'main.hbs', helpers: { section(name, options) { if (!this._sections) this._sections = {}; this._sections[name] = options.fn(this); return null; }, }, })); app.set('view engine','hbs'); app.set('views','./view'); app.get("/", (req, res) => { res.render("login"); }) app.listen(3000, () => console.log("listening"));

principal.hbs

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> {{{body}}} {{{_section.js}}} </body> </html>

iniciar sesión.hbs

 <h1>Hello</h1> {{#section "js"}} <script> console.log("hello world") </script> {{/section}}

Editar

Tampoco puedo incrustar HTML

iniciar sesión.hbs

 <h1>Hello</h1> {{#section "js"}} <p>a paragraph</p> {{/section}}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intenté ejecutarlo. La verdadera razón por la que no se está procesando es porque dentro de su main.hbs necesita tener {{{_sections.js}}} dentro de las etiquetas del cuerpo html en lugar de solo {{{_section.js}}} como lo tiene ahora . La etiqueta del script también debería ejecutarse.

Disculpa la confusión con la respuesta anterior.

about 4 years ago · Juan Pablo Isaza Report
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!