0

I have an array known as sem containing multiple objects and an object known as result containing properties href and content which contain strings. They are being rendered to the view as follows:

Here i am using async to run functions in parallel so that i can pass 2 different variables into the view. Reference

app.js

res.render('sem/semester', {
  sem: sem,
  result:result
});

The array sem contains:

sem: [
{semNumber: 2, collegeName: 'blalblalbla'},
{semNumber: 3, collegeName: 'dfhgfh'}
{semNumber: 4, collegeName: 'dsfdsdsf'}
];

The object result contains:

result: {href: 'url', content: 'Some text'}

TARGET

In semester.handlebars

{{#each sem}}
    <div>{{semNumber}}</div>
    <div>{{collegeName}}</div>
    <a href="{{result.href}}">{{result.content}}</a>
{{/each}}

I did the above, but the properties of result i.e href & content do not get displayed in an each loop.

Output must be:

2
blablablabla
Some text
3
dfhgfh
Some text
4
dsfdsdsf
Some text

EDIT: (The url contains a handlebar expression which would render from the array sem)

Example: /marks/edit_marks/semester_number={{semNumber}}/{{id}}

  • Try `{{../result.href}}` – elclanrs Jan 06 '18 at 07:32
  • Thanks @elclanrs . It worked, but handlebar expression is rendered as static text in the href. Sorry i forgot to mention it when i wrote the post :( – Dargahwala Idrees Jan 06 '18 at 09:04
  • Could you please update your question with full html example of expected output generated by single iteration of `{{each}}` and json data for which it was generated? – wscourge Jan 23 '18 at 11:46

0 Answers0