Built-in Functions
The template to output the database result in a HTML table <table> <tr><th>&nbsp;</th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr> {section name=co loop=$contacts} <tr> <td><a href="view.php?id={$contacts[co].id}">view<a></td> <td>{$contacts[co].name}</td> <td>{$contacts[co].home}</td> <td>{$contacts[co].cell}</td> <td>{$contacts[co].email}</td> <tr> {sectionelse} <tr><td colspan="5">No items found</td></tr> {/section} </table>
.index index contains the current array index, starting with zero or the start attribute if given. It increments by one or by the step attribute if given. Technical Note: If the step and start properties are not modified, then this works the same as the iteration property, except it starts at zero instead of one.
Example 7.37. {section} index property
FYI: $custid[customer.index] and $custid[customer] are identical. {section name=customer loop=$custid} {$smarty.section.customer.index} id: {$custid[customer]}<br /> {/section}
The above example will output: 0 id: 1000<br /> 1 id: 1001<br /> 2 id: 1002<br />
.index_prev index_prev is the previous loop index. On the first loop, this is set to -1.
.index_next index_next is the next loop index. On the last loop, this is still one more than the current index, respecting the setting of the step attribute, if given.
Example 7.38. index, index_next and index_prev properties <?php $data = array(1001,1002,1003,1004,1005);
62