Search code examples
node.jshandlebars.jsexpress-handlebars

What would be the equivalent of following code in .hbs file


I was working on a project involving node, mongoose, handlebars, express. What would be the equivalent of the following code in handlebars?

<div class="panel panel-default" ng-init="getExams()">
 <div class="panel-heading">
    <h3 class="panel-title">Exams</h3>
 </div>
<div class="panel-body">
 <div class="row">
  <div ng-repeat="exam in exams">
    <div class="col-md-6">
      <div class="col-md-6">
        <h4>{{exam.examName}}</h4>
        <a class="btn btn-primary" href="#/exams/details/{{exam._id}}">View Details</a>
      </div>
    </div>
  </div>
</div>

I want to display all the rows of the output of the following function in my model.

module.exports.getExams = (callback, limit) => {
Exam.find(callback).limit(limit);
}

Solution

  • In node.js, when you're rendering : res.render('your view'),{exams:exams} In handlebars :

    <div class="panel panel-default">
     <div class="panel-heading">
        <h3 class="panel-title">Exams</h3>
     </div>
    <div class="panel-body">
     <div class="row">
     {{#each exams}}
      <div>
        <div class="col-md-6">
          <div class="col-md-6">
            <h4>{{examName}}</h4>
            <a class="btn btn-primary" href="#/exams/details/{{_id}}">View Details</a>
          </div>
        </div>
      </div>
     {{/each}}
    </div>