'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.
Solution 1:[1]
I'm assuming you are passing variables into your template from express controller that is rendering the html page.
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.
Solution 2:[2]
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 }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hackbyrd |
| Solution 2 | Sagar Darekar |
