0

Inside a foreach loop in HBS I am trying to display the data which is inside a different variable.

Here's the route and the data which is being passed to the hbs:

const info = [
    {
        name: "kakashi",
        age: 22,
        gender: "Male"
    },
    {
        name:"Samsung",
        age: 34,
        gender: "Male"
    }
]
const num = 2234453453;

app.get('/', (req,res)=>{
    res.render('index', {info, num})
}); 

app.listen(8000);

Here's my front end :

{{#each info as |d|}}
        {{d.name}}
        {{num}}
    {{/each}}

here each loop is working fine, but why is the data inside the num not being displayed

Kakashi Hatake
  • 133
  • 1
  • 9
  • 1
    You need to change the data context. See: https://handlebarsjs.com/guide/expressions.html#changing-the-context – 76484 Nov 04 '21 at 15:36
  • Thanks, I don't know what data context is but writing my ``num`` in ``{{../num}}`` this manner did the trick, so can you officially write an ans to this problem so that I can close it. – Kakashi Hatake Nov 04 '21 at 15:43

0 Answers0