ghost

Built-in even and odd block helpers on the Ghost blogging platform

Ghost has a few built-in block helpers that extend the templating capabilities of handlebars. Two of these helpers are @even and @odd.

The following snippet will iterate through all of the posts in the current context, and apply the class even or odd depending on the lteration of the loop.

{{#foreach posts}}
    <div class="{{#if @even}}even{{else}}odd{{/if}}">{{title}}</div>
{{/foreach}}

This will output markup similar to below

<div class="even">post 1</div>
<div class="odd">post 2</div>
<div class="even">post 3</div>
<div class="odd">post 4</div>
<div class="even">post 5</div>
<div class="odd">post 6</div>

more ghost posts