<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{section},{sectionelse}</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="language.builtin.functions.html" title="Chapter 7. Built-in Functions"> <link rel="prev" href="language.function.php.html" title="{php}"> <link rel="next" href="language.function.strip.html" title="{strip}"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{section},{sectionelse}</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.function.php.html">Prev</a> </td> <th width="60%" align="center">Chapter 7. Built-in Functions</th> <td width="20%" align="right"> <a accesskey="n" href="language.function.strip.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="{section},{sectionelse}"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.function.section"></a>{section},{sectionelse}</h2></div></div></div> <p> A <code class="varname">{section}</code> is for looping over <span class="bold"><strong>sequentially indexed arrays of data</strong></span>, unlike <a class="link" href="language.function.foreach.html" title="{foreach},{foreachelse}"><code class="varname">{foreach}</code></a> which is used to loop over a <span class="bold"><strong>single associative array</strong></span>. Every <code class="varname">{section}</code> tag must be paired with a closing <code class="varname">{/section}</code> tag. </p> <div class="informaltable"><table border="1"> <colgroup> <col align="center"> <col align="center"> <col align="center"> <col align="center"> <col> </colgroup> <thead><tr> <th align="center">Attribute Name</th> <th align="center">Type</th> <th align="center">Required</th> <th align="center">Default</th> <th>Description</th> </tr></thead> <tbody> <tr> <td align="center">name</td> <td align="center">string</td> <td align="center">Yes</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>The name of the section</td> </tr> <tr> <td align="center">loop</td> <td align="center">mixed</td> <td align="center">Yes</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>Value to determine the number of loop iterations</td> </tr> <tr> <td align="center">start</td> <td align="center">integer</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>0</em></span></td> <td>The index position that the section will begin looping. If the value is negative, the start position is calculated from the end of the array. For example, if there are seven values in the loop array and start is -2, the start index is 5. Invalid values (values outside of the length of the loop array) are automatically truncated to the closest valid value.</td> </tr> <tr> <td align="center">step</td> <td align="center">integer</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>1</em></span></td> <td>The step value that will be used to traverse the loop array. For example, step=2 will loop on index 0,2,4, etc. If step is negative, it will step through the array backwards.</td> </tr> <tr> <td align="center">max</td> <td align="center">integer</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>Sets the maximum number of times the section will loop.</td> </tr> <tr> <td align="center">show</td> <td align="center">boolean</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td> <td>Determines whether or not to show this section</td> </tr> </tbody> </table></div> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> Required attributes are <em class="parameter"><code>name</code></em> and <em class="parameter"><code>loop</code></em>. </p></li> <li class="listitem"><p> The <em class="parameter"><code>name</code></em> of the <code class="varname">{section}</code> can be anything you like, made up of letters, numbers and underscores, like <a class="ulink" href="http://php.net/language.variables" target="_top">PHP variables</a>. </p></li> <li class="listitem"><p> {section}'s can be nested, and the nested <code class="varname">{section}</code> names must be unique from each other. </p></li> <li class="listitem"><p> The <em class="parameter"><code>loop</code></em> attribute, usually an array of values, determines the number of times the <code class="varname">{section}</code> will loop. You can also pass an integer as the loop value. </p></li> <li class="listitem"><p>When printing a variable within a <code class="varname">{section}</code>, the <code class="varname">{section}</code> <em class="parameter"><code>name</code></em> must be given next to variable name within [brackets]. </p></li> <li class="listitem"><p> <code class="varname">{sectionelse}</code> is executed when there are no values in the loop variable. </p></li> <li class="listitem"><p> A <code class="varname">{section}</code> also has its own variables that handle <code class="varname">{section}</code> properties. These properties are accessible as: <a class="link" href="language.variables.smarty.html#language.variables.smarty.loops" title="{$smarty.section}, {$smarty.foreach}"> <em class="parameter"><code>{$smarty.section.name.property}</code></em></a> where <span class="quote">“<span class="quote">name</span>”</span> is the attribute <em class="parameter"><code>name</code></em>. </p></li> <li class="listitem"><p> <code class="varname">{section}</code> properties are <a class="link" href="language.function.section.html#section.property.index" title=".index"><em class="parameter"><code>index</code></em></a>, <a class="link" href="language.function.section.html#section.property.index.prev" title=".index_prev"><em class="parameter"><code>index_prev</code></em></a>, <a class="link" href="language.function.section.html#section.property.index.next" title=".index_next"><em class="parameter"><code>index_next</code></em></a>, <a class="link" href="language.function.section.html#section.property.iteration" title=".iteration"><em class="parameter"><code>iteration</code></em></a>, <a class="link" href="language.function.section.html#section.property.first" title=".first"><em class="parameter"><code>first</code></em></a>, <a class="link" href="language.function.section.html#section.property.last" title=".last"><em class="parameter"><code>last</code></em></a>, <a class="link" href="language.function.section.html#section.property.rownum" title=".rownum"><em class="parameter"><code>rownum</code></em></a>, <a class="link" href="language.function.section.html#section.property.loop" title=".loop"><em class="parameter"><code>loop</code></em></a>, <a class="link" href="language.function.section.html#section.property.show" title=".show"><em class="parameter"><code>show</code></em></a>, <a class="link" href="language.function.section.html#section.property.total" title=".total"><em class="parameter"><code>total</code></em></a>. </p></li> </ul></div> <div class="example"> <a name="id3054919"></a><p class="title"><b>Example 7.30. Looping a simple array with {section}</b></p> <div class="example-contents"> <p> <a class="link" href="api.assign.html" title="assign()"><code class="varname">assign()</code></a> an array to Smarty </p> <pre class="programlisting"> <?php $data = array(1000,1001,1002); $smarty->assign('custid',$data); ?> </pre> <p>The template that outputs the array</p> <pre class="programlisting"> {* this example will print out all the values of the $custid array *} {section name=customer loop=$custid} id: {$custid[customer]}<br /> {/section} <hr /> {* print out all the values of the $custid array reversed *} {section name=foo loop=$custid step=-1} {$custid[foo]}<br /> {/section} </pre> <p> The above example will output: </p> <pre class="screen"> id: 1000<br /> id: 1001<br /> id: 1002<br /> <hr /> id: 1002<br /> id: 1001<br /> id: 1000<br /> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3054977"></a><p class="title"><b>Example 7.31. {section} without an assigned array</b></p> <div class="example-contents"> <pre class="programlisting"> {section name=foo start=10 loop=20 step=2} {$smarty.section.foo.index} {/section} <hr /> {section name=bar loop=21 max=6 step=-2} {$smarty.section.bar.index} {/section} </pre> <p> The above example will output: </p> <pre class="screen"> 10 12 14 16 18 <hr /> 20 18 16 14 12 10 </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3055012"></a><p class="title"><b>Example 7.32. Naming a {section}</b></p> <div class="example-contents"> <p>The <em class="parameter"><code>name</code></em> of the <code class="varname">{section}</code> can be anything you like, see <a class="ulink" href="http://php.net/language.variables" target="_top">PHP variables</a>. It is used to reference the data within the <code class="varname">{section}</code>.</p> <pre class="programlisting"> {section name=anything loop=$myArray} {$myArray[anything].foo} {$name[anything]} {$address[anything].bar} {/section} </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3055047"></a><p class="title"><b>Example 7.33. Looping an associative array with {section}</b></p> <div class="example-contents"> <p>This is an example of printing an associative array of data with a <code class="varname">{section}</code>. Following is the php script to assign the <em class="parameter"><code>$contacts</code></em> array to Smarty.</p> <pre class="programlisting"> <?php $data = array( array('name' => 'John Smith', 'home' => '555-555-5555', 'cell' => '666-555-5555', 'email' => 'john@myexample.com'), array('name' => 'Jack Jones', 'home' => '777-555-5555', 'cell' => '888-555-5555', 'email' => 'jack@myexample.com'), array('name' => 'Jane Munson', 'home' => '000-555-5555', 'cell' => '123456', 'email' => 'jane@myexample.com') ); $smarty->assign('contacts',$data); ?> </pre> <p>The template to output <em class="parameter"><code>$contacts</code></em></p> <pre class="programlisting"> {section name=customer loop=$contacts} <p> name: {$contacts[customer].name}<br /> home: {$contacts[customer].home}<br /> cell: {$contacts[customer].cell}<br /> e-mail: {$contacts[customer].email} </p> {/section} </pre> <p> The above example will output: </p> <pre class="screen"> <p> name: John Smith<br /> home: 555-555-5555<br /> cell: 666-555-5555<br /> e-mail: john@myexample.com </p> <p> name: Jack Jones<br /> home phone: 777-555-5555<br /> cell phone: 888-555-5555<br /> e-mail: jack@myexample.com </p> <p> name: Jane Munson<br /> home phone: 000-555-5555<br /> cell phone: 123456<br /> e-mail: jane@myexample.com </p> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3054440"></a><p class="title"><b>Example 7.34. {section} demonstrating the <code class="varname">loop</code> variable</b></p> <div class="example-contents"> <p>This example assumes that <em class="parameter"><code>$custid</code></em>, <em class="parameter"><code>$name</code></em> and <em class="parameter"><code>$address</code></em> are all arrays containing the same number of values. First the php script that assign's the arrays to Smarty.</p> <pre class="programlisting"> <?php $id = array(1001,1002,1003); $smarty->assign('custid',$id); $fullnames = array('John Smith','Jack Jones','Jane Munson'); $smarty->assign('name',$fullnames); $addr = array('253 Abbey road', '417 Mulberry ln', '5605 apple st'); $smarty->assign('address',$addr); ?> </pre> <p>The <em class="parameter"><code>loop</code></em> variable only determines the number of times to loop. You can access ANY variable from the template within the <code class="varname">{section}</code></p> <pre class="programlisting"> {section name=customer loop=$custid} <p> id: {$custid[customer]}<br /> name: {$name[customer]}<br /> address: {$address[customer]} </p> {/section} </pre> <p> The above example will output: </p> <pre class="screen"> <p> id: 1000<br /> name: John Smith<br /> address: 253 Abbey road </p> <p> id: 1001<br /> name: Jack Jones<br /> address: 417 Mulberry ln </p> <p> id: 1002<br /> name: Jane Munson<br /> address: 5605 apple st </p> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3055364"></a><p class="title"><b>Example 7.35. Nested {section}'s</b></p> <div class="example-contents"> <p> {section}'s can be nested as deep as you like. With nested {section}'s, you can access complex data structures, such as multi-dimensional arrays. This is an example <code class="filename">.php</code> script thats assign's the arrays. </p> <pre class="programlisting"> <?php $id = array(1001,1002,1003); $smarty->assign('custid',$id); $fullnames = array('John Smith','Jack Jones','Jane Munson'); $smarty->assign('name',$fullnames); $addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st'); $smarty->assign('address',$addr); $types = array( array( 'home phone', 'cell phone', 'e-mail'), array( 'home phone', 'web'), array( 'cell phone') ); $smarty->assign('contact_type', $types); $info = array( array('555-555-5555', '666-555-5555', 'john@myexample.com'), array( '123-456-4', 'www.example.com'), array( '0457878') ); $smarty->assign('contact_info', $info); ?> </pre> <p>In this template, <span class="emphasis"><em>$contact_type[customer]</em></span> is an array of contact types for the current customer.</p> <pre class="programlisting"> {section name=customer loop=$custid} <hr> id: {$custid[customer]}<br /> name: {$name[customer]}<br /> address: {$address[customer]}<br /> {section name=contact loop=$contact_type[customer]} {$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br /> {/section} {/section} </pre> <p> The above example will output: </p> <pre class="screen"> <hr> id: 1000<br /> name: John Smith<br /> address: 253 N 45th<br /> home phone: 555-555-5555<br /> cell phone: 666-555-5555<br /> e-mail: john@myexample.com<br /> <hr> id: 1001<br /> name: Jack Jones<br /> address: 417 Mulberry ln<br /> home phone: 123-456-4<br /> web: www.example.com<br /> <hr> id: 1002<br /> name: Jane Munson<br /> address: 5605 apple st<br /> cell phone: 0457878<br /> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3055457"></a><p class="title"><b>Example 7.36. Database example with a {sectionelse}</b></p> <div class="example-contents"> <p>Results of a database search (eg ADODB or PEAR) are assigned to Smarty</p> <pre class="programlisting"> <?php $sql = 'select id, name, home, cell, email from contacts ' ."where name like '$foo%' "; $smarty->assign('contacts', $db->getAll($sql)); ?> </pre> <p>The template to output the database result in a HTML table</p> <pre class="programlisting"> <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> </pre> </div> </div> <br class="example-break"><div class="sect2" title=".index"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.index"></a>.index</h3></div></div></div> <p> <em class="parameter"><code>index</code></em> contains the current array index, starting with zero or the <em class="parameter"><code>start</code></em> attribute if given. It increments by one or by the <em class="parameter"><code>step</code></em> attribute if given. </p> <div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Technical Note</h3> <p> If the <em class="parameter"><code>step</code></em> and <em class="parameter"><code>start</code></em> properties are not modified, then this works the same as the <a class="link" href="language.function.section.html#section.property.iteration" title=".iteration"><em class="parameter"><code>iteration</code></em></a> property, except it starts at zero instead of one. </p> </div> <div class="example"> <a name="id3055587"></a><p class="title"><b>Example 7.37. {section} <code class="varname">index</code> property</b></p> <div class="example-contents"> <p> </p> <div class="note" title="FYI" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">FYI</h3> <p><code class="literal">$custid[customer.index]</code> and <code class="literal">$custid[customer]</code> are identical.</p> </div> <p> </p> <pre class="programlisting"> {section name=customer loop=$custid} {$smarty.section.customer.index} id: {$custid[customer]}<br /> {/section} </pre> <p> The above example will output: </p> <pre class="screen"> 0 id: 1000<br /> 1 id: 1001<br /> 2 id: 1002<br /> </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".index_prev"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.index.prev"></a>.index_prev</h3></div></div></div> <p> <em class="parameter"><code>index_prev</code></em> is the previous loop index. On the first loop, this is set to -1. </p> </div> <div class="sect2" title=".index_next"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.index.next"></a>.index_next</h3></div></div></div> <p> <em class="parameter"><code>index_next</code></em> is the next loop index. On the last loop, this is still one more than the current index, respecting the setting of the <em class="parameter"><code>step</code></em> attribute, if given. </p> <div class="example"> <a name="id3055690"></a><p class="title"><b>Example 7.38. <code class="varname">index</code>, <code class="varname">index_next</code> and <code class="varname">index_prev</code> properties </b></p> <div class="example-contents"> <pre class="programlisting"> <?php $data = array(1001,1002,1003,1004,1005); $smarty->assign('rows',$data); ?> </pre> <p>Template to output the above array in a table</p> <pre class="programlisting"> {* $rows[row.index] and $rows[row] are identical in meaning *} <table> <tr> <th>index</th><th>id</th> <th>index_prev</th><th>prev_id</th> <th>index_next</th><th>next_id</th> </tr> {section name=row loop=$rows} <tr> <td>{$smarty.section.row.index}</td><td>{$rows[row]}</td> <td>{$smarty.section.row.index_prev}</td><td>{$rows[row.index_prev]}</td> <td>{$smarty.section.row.index_next}</td><td>{$rows[row.index_next]}</td> </tr> {/section} </table> </pre> <p> The above example will output a table containing the following: </p> <pre class="screen"> index id index_prev prev_id index_next next_id 0 1001 -1 1 1002 1 1002 0 1001 2 1003 2 1003 1 1002 3 1004 3 1004 2 1003 4 1005 4 1005 3 1004 5 </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".iteration"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.iteration"></a>.iteration</h3></div></div></div> <p> <em class="parameter"><code>iteration</code></em> contains the current loop iteration and starts at one. </p> <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> This is not affected by the <code class="varname">{section}</code> properties <em class="parameter"><code>start</code></em>, <em class="parameter"><code>step</code></em> and <em class="parameter"><code>max</code></em>, unlike the <a class="link" href="language.function.section.html#section.property.index" title=".index"><em class="parameter"><code>index</code></em></a> property. <em class="parameter"><code>iteration</code></em> also starts with one instead of zero unlike <em class="parameter"><code>index</code></em>. <a class="link" href="language.function.section.html#section.property.rownum" title=".rownum"><em class="parameter"><code>rownum</code></em></a> is an alias to <em class="parameter"><code>iteration</code></em>, they are identical. </p> </div> <div class="example"> <a name="id3055853"></a><p class="title"><b>Example 7.39. A section's <code class="varname">iteration</code> property </b></p> <div class="example-contents"> <pre class="programlisting"> <?php // array of 3000 to 3015 $id = range(3000,3015); $smarty->assign('arr',$id); ?> </pre> <p>Template to output every other element of the <code class="literal">$arr</code> array as <code class="literal">step=2</code></p> <pre class="programlisting"> {section name=cu loop=$arr start=5 step=2} iteration={$smarty.section.cu.iteration} index={$smarty.section.cu.index} id={$custid[cu]}<br /> {/section} </pre> <p> The above example will output: </p> <pre class="screen"> iteration=1 index=5 id=3005<br /> iteration=2 index=7 id=3007<br /> iteration=3 index=9 id=3009<br /> iteration=4 index=11 id=3011<br /> iteration=5 index=13 id=3013<br /> iteration=6 index=15 id=3015<br /> </pre> <p> Another example that uses the <em class="parameter"><code>iteration</code></em> property to output a table header block every five rows. Uses the <a class="link" href="language.function.if.html" title="{if},{elseif},{else}"><code class="varname">{if}</code></a> function with the mod operator. </p> <pre class="programlisting"> <table> {section name=co loop=$contacts} {if $smarty.section.co.iteration % 5 == 1} <tr><th>&nbsp;</th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr> {/if} <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> {/section} </table> </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".first"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.first"></a>.first</h3></div></div></div> <p> <em class="parameter"><code>first</code></em> is set to <code class="constant">TRUE</code> if the current <code class="varname">{section}</code> iteration is the initial one. </p> </div> <div class="sect2" title=".last"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.last"></a>.last</h3></div></div></div> <p> <em class="parameter"><code>last</code></em> is set to <code class="constant">TRUE</code> if the current section iteration is the final one. </p> <div class="example"> <a name="id3056009"></a><p class="title"><b>Example 7.40. {section} property <code class="varname">first</code> and <code class="varname">last</code></b></p> <div class="example-contents"> <p> This example loops the <code class="varname">$customers</code> array, outputs a header block on the first iteration and on the last outputs the footer block. Also uses the <a class="link" href="language.function.section.html#section.property.total" title=".total"><em class="parameter"><code>total</code></em></a> property. </p> <pre class="programlisting"> {section name=customer loop=$customers} {if $smarty.section.customer.first} <table> <tr><th>id</th><th>customer</th></tr> {/if} <tr> <td>{$customers[customer].id}}</td> <td>{$customers[customer].name}</td> </tr> {if $smarty.section.customer.last} <tr><td></td><td>{$smarty.section.customer.total} customers</td></tr> </table> {/if} {/section} </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".rownum"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.rownum"></a>.rownum</h3></div></div></div> <p> <em class="parameter"><code>rownum</code></em> contains the current loop iteration, starting with one. It is an alias to <a class="link" href="language.function.section.html#section.property.iteration" title=".iteration"><em class="parameter"><code>iteration</code></em></a>, they work identically. </p> </div> <div class="sect2" title=".loop"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.loop"></a>.loop</h3></div></div></div> <p> <em class="parameter"><code>loop</code></em> contains the last index number that this {section} looped. This can be used inside or after the <code class="varname">{section}</code>. </p> <div class="example"> <a name="id3056117"></a><p class="title"><b>Example 7.41. {section} property <code class="varname">loop</code></b></p> <div class="example-contents"> <pre class="programlisting"> {section name=customer loop=$custid} {$smarty.section.customer.index} id: {$custid[customer]}<br /> {/section} There are {$smarty.section.customer.loop} customers shown above. </pre> <p> The above example will output: </p> <pre class="screen"> 0 id: 1000<br /> 1 id: 1001<br /> 2 id: 1002<br /> There are 3 customers shown above. </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".show"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.show"></a>.show</h3></div></div></div> <p> <em class="parameter"><code>show</code></em> is used as a parameter to section and is a boolean value. If <code class="constant">FALSE</code>, the section will not be displayed. If there is a <code class="varname">{sectionelse}</code> present, that will be alternately displayed. </p> <div class="example"> <a name="id3056180"></a><p class="title"><b>Example 7.42. <code class="varname">show</code> property </b></p> <div class="example-contents"> <p>Boolean <code class="varname">$show_customer_info</code> has been passed from the PHP application, to regulate whether or not this section shows.</p> <pre class="programlisting"> {section name=customer loop=$customers show=$show_customer_info} {$smarty.section.customer.rownum} id: {$customers[customer]}<br /> {/section} {if $smarty.section.customer.show} the section was shown. {else} the section was not shown. {/if} </pre> <p> The above example will output: </p> <pre class="screen"> 1 id: 1000<br /> 2 id: 1001<br /> 3 id: 1002<br /> the section was shown. </pre> </div> </div> <br class="example-break"> </div> <div class="sect2" title=".total"> <div class="titlepage"><div><div><h3 class="title"> <a name="section.property.total"></a>.total</h3></div></div></div> <p> <em class="parameter"><code>total</code></em> contains the number of iterations that this <code class="varname">{section}</code> will loop. This can be used inside or after a <code class="varname">{section}</code>. </p> <div class="example"> <a name="id3056253"></a><p class="title"><b>Example 7.43. <code class="varname">total</code> property example</b></p> <div class="example-contents"><pre class="programlisting"> {section name=customer loop=$custid step=2} {$smarty.section.customer.index} id: {$custid[customer]}<br /> {/section} There are {$smarty.section.customer.total} customers shown above. </pre></div> </div> <br class="example-break"><p> See also <a class="link" href="language.function.foreach.html" title="{foreach},{foreachelse}"><code class="varname">{foreach}</code></a> and <a class="link" href="language.variables.smarty.html#language.variables.smarty.loops" title="{$smarty.section}, {$smarty.foreach}"><em class="parameter"><code>$smarty.section</code></em></a>. </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="language.function.php.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="language.builtin.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="language.function.strip.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">{php} </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> {strip}</td> </tr> </table> </div> </body> </html>