randombits
randombits

Reputation: 48450

EmberJS/handlebars how to add a class to every other tag in each loop

I currently have some markup that looks like the following in my Ember.js app that uses Handlebars for templating:

 {{#each block in controller.gameBlocks}}
        <div class="row-fluid">
            {{#each game in block.games}}
                <div class="span6 span6_first-child">
         ... more stuff ...
 {{/#each}}

The problem I have here is I don't want to include the class span6_first-child in every other iteration of the each statement above or every even numbered index number if we were to have an each_with_index type loop. Is this trivial to do with handlebars/ember.js?

Upvotes: 1

Views: 615

Answers (1)

Christopher Marshall
Christopher Marshall

Reputation: 10736

Remove that class and apply it's css rules to a new selector using pseudo selectors. As far as I know, there's no constructs for even/odd/every other built into handlebars.

<div class="row-fluid">
            {{#each game in block.games}}
                <div class="span6">
         ... more stuff ...


.row-fluid .span6:nth-child(odd) {
 /* Prior rules here */
}

Upvotes: 1

Related Questions