Question: I am passing an array of objects to jQuery template (official `jquery-tmpl` plugin):

```
$("#itemTmpl").tmpl(items).appendTo("body");

<script id="itemTmpl" type="text/x-jquery-tmpl">
    <div class="item">Name: ${name}, Index: ${???}</div>
</script>

```

What is the easiest way to display item index in the template? Preferably without using separated external functions, without changing passed object structure, and without changing template structure (converting to `{{each}}`). Is there any built-in variable perhaps that stores current array index?

**UPDATE**
I created [a ticket](http://bugs.jquery.com/ticket/7137) proposing to expose array index to template item but it was closed as invalid...

Answer: 
<https://github.com/clarkbox/jquery-tmpl/commit/993e6fa128c5991723316032abe12ff0cbbb9805>

Patch you jquery.template and then you can do like this:

```
<script id=”tabTemplate” type=”text/x-jquery-tmpl”>
    <div id=“tab-${$index + 1}”>
        <!— render tab contents here… —>
    </div>
</script>

```
simply define one global variable for counting:

```
var n = 0;
function outputTemplate(){
    return $( "#template_item" ).tmpl(datas,
          {
              getEvenOrOdd: function(){
                  return ++n % 2 == 0 ? 'odd' : 'even';
              }
          } 
    );
}

```