I'm using Meteor and trying to get around the lack of the Handlebars @index. I'm getting close. I've implemented a counter, and a few helper functions:
initCounter
initializes the counter to 0incCounterMod
increments the counter and applies the modulo to get every X numbercounterIs
simply checks the counter is a particular number X
All this basically to get a three items per row on my output. Here is a sample:
{{initCounter}}
<div class="row-fluid">
{{#each list}}
<span></span>
{{incCounterMod 3}}
{{#if counterIs 0}}
</div><div class="row-fluid">
{{/if}}
{{/each}}
</div>
As you can see, I'm trying to end one <div>
and start another. I should get output like:
<div class="row-fluid">
<span></span>
<span></span>
<span></span>
</div>
<div class="row-fluid">
<span></span>
<span></span>
<span></span>
</div>
...
The problem is... Handlebars or Meteor seems to be "fixing" or "logically matching" my div
blocks by reversing the </div><div class="row-fluid">
tags, so that my output is:
<div class="row-fluid">
<span></span>
<span></span>
<span></span>
<div class="row-fluid"></div>
<span></span>
<span></span>
<span></span>
<div class="row-fluid"></div>
<span></span>
...
</div>
Kinda silly, since I didn't ask for that. I'm trying to end one <div>
and start another, not match them up according to where they appear in the source code. (Note: console debugging suggests that all the counters and stuff are working well.)
Is there a way to get around this? I thought Handlebars just rendered html text as it goes ... I guess I may be wrong.
Thanks.