简体   繁体   中英

How can i pass a variable from a loop (HandleBar template) to Express helper To get some result?

I want to pass a ID to fetch the results such as Status, From Handlebar template to express helper

I have tried HBS helper but as far my searched results show me that i can't do any SYNC in hbs helper until i use any express helper. Like as, app.use(some express helper).

hbs template

{{#result}}
  {{need to call and get value from express helper}}
{{/result}}

But i want use that function only once a time not on every single request. I don't know that, my tried method was right or any other better way to come out with the best results.

Here some Images: 1 [Route.js file] 2 [View.hbs File]

  1. I'm assuming you are passing variables into your template from express controller that is rendering the html page.

  2. If the above is true, you can just pass in the function from the controller as if you would a variable to the html page.

Let me know if that makes sense.

In Express file you declare the route and declare the error variable

app.post("/login", async (req, res) => {
      return res.status(404).render("login",{stuff:"Password is Incorrect!!"});
});

In HBS Login file simply write variable name

{{ stuff }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM