Ho to format an each loop in a bootstrap table


#1

I would like to format and each loop in a bootstrap table So this is my code of my bookshelper.js file:

Template.books.helpers({
'book': function(){ 
    return Books.find();
    }     
});

In my books.html file I’ve added a bootstrap table:

<table class="table table-striped">
<thead>
 <tr>
  <th>Author</th>
  <th>Title</th>
 </tr>
</thead>
<tbody>
    <tr>         
 {{#each book}}
	<td>{{author}}  </td> 
        <td>{{title}}  </td>       
 {{/each}}     
    </tr>  
</tbody>
</table>

but the results I am getting looping in my Books collection is the following
http://gyazo.com/6a124f5cc954d6e11c531fd862ac2c8d
As you can see the list is not formatted properly. Can you please assist? Maybe I am
placing the each loop in a wrong way. Thanks a lot! Sandro


#2

Your {{#each}} has to include the <td> tag as well.

Try:

<table class="table table-striped">
<thead>
 <tr>
  <th>Author</th>
  <th>Title</th>
 </tr>
</thead>
<tbody>         
 {{#each book}}
    <tr>
	<td>{{author}}</td> 
        <td>{{title}}</td>       
    </tr>
 {{/each}}       
</tbody>
</table>

#3

Thanks a lot! It works))


#5

But how do I do it if I want to make every fourth <td> as new <tr>
For example…

<table><tr>
  {{#each array_result}}
    {{if count%4 ===0}}</tr><tr>{{/if}}
      <td>{{value}}</td>
      {{count++}}
  {{/each}}
</tr></table>

when I try to create </tr><tr> it throws an error.