Search code examples
jqueryjtemplates

Local variable/for loop in jTemplates


Is it possible to create a local variable or a for loop (instead of foreach) in a jtemplate? I want to give unique id's to the HTML elements and need a counter or something. Thanks!


Solution

  • use $index

    $index - index of the element in the table
    $iteration - ID of the iteration (the next number begins from 0)
    $first - is this the first iteration?
    $last - is this the last iteration?
    $total - the total number of iterations
    

    ex

    {#foreach $T.Rows as row}
      $T.row$index
    {#/for}
    

    read http://www.codeproject.com/Articles/45759/jQuery-jTemplates-Grid