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}}

3
  • Try {{../result.href}} Commented Jan 6, 2018 at 7: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 :( Commented Jan 6, 2018 at 9: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? Commented Jan 23, 2018 at 11:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.