These are chat archives for canjs/canjs

19th
May 2017
Viktor Busko
@Lighttree
May 19 2017 09:12

maybe someone can suggest something interesting. I have a collection and in my markup at some step of iteration I need to wrap following items into div.
So the idea is:

{{#each comments}}
        {{#is @index commentsToShow}}
        <div class="secondPart">
        {{/is}}
        <comment-item comment="{.}"></comment-item>
{{/each}}
{{#moreThanShowLimit}}
         </div>
{{/moreThanShowLimit}}

But stache/mustache inserts div and browser closes it automatically and closing tag ignored at all. What is better way to do the same thing ?
I would like to avoid creating separate collection in viewModel, so I was thinking about some kind of extended #customEach helper and use it like...

{{#each comments from=0 to=commentsToShow}}
        <comment-item comment="{.}"></comment-item>
{{/each}}
<div class="secondPart">
{{#each comments from=commentsToShow to=comments.length}}
        <comment-item comment="{.}"></comment-item>
{{/each}}
</div>

Maybe someone can suggest easier way ? Using what we have in stache out of the box ?

Kevin Phillips
@phillipskevin
May 19 2017 13:42

would one of these work?

        {{#is %index commentsToShow}}
        <div class="secondPart">
        {{/is}}
          <comment-item comment="{.}"></comment-item>
        {{#is %index commentsToShow}}
        </div>
        {{/is}}

or

        {{#is %index commentsToShow}}
        <div class="secondPart”>
          <comment-item comment="{.}"></comment-item>
        </div>
        {{else}}
        <comment-item comment="{.}"></comment-item>
        {{/is}}
might be simpler than writing your own each helper @Lighttree