Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 8377d4bb25a3992aad680df2952f4b71 > files > 91

php-smarty-doc-2.6.26-1mdv2010.0.noarch.rpm

<HTML
><HEAD
><TITLE
>{section},{sectionelse}</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Smarty Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Built-in Functions"
HREF="language.builtin.functions.html"><LINK
REL="PREVIOUS"
TITLE="{php}"
HREF="language.function.php.html"><LINK
REL="NEXT"
TITLE="{strip}"
HREF="language.function.strip.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Smarty Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="language.function.php.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 7. Built-in Functions</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.function.strip.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.function.section"
></A
>{section},{sectionelse}</H1
><P
>&#13;  A <TT
CLASS="varname"
>{section}</TT
>
  is for looping over <SPAN
CLASS="bold"
><B
CLASS="emphasis"
>arrays of data</B
></SPAN
>,
  unlike <A
HREF="language.function.foreach.html"
><TT
CLASS="varname"
>{foreach}</TT
></A
>
  which is used to loop over a
   <SPAN
CLASS="bold"
><B
CLASS="emphasis"
>single associative array</B
></SPAN
>.
  Every <TT
CLASS="varname"
>{section}</TT
> tag must be paired with
   a closing <TT
CLASS="varname"
>{/section}</TT
> tag.
   </P
><DIV
CLASS="informaltable"
><A
NAME="AEN2324"
></A
><P
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Attribute Name</TH
><TH
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Type</TH
><TH
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Required</TH
><TH
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Default</TH
><TH
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>name</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>string</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Yes</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>n/a</I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>The name of the section</TD
></TR
><TR
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>loop</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>mixed</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>Yes</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>n/a</I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>Value to determine the number of loop iterations</TD
></TR
><TR
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>start</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>integer</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>No</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>0</I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>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
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>step</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>integer</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>No</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>1</I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>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
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>max</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>integer</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>No</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>n/a</I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>Sets the maximum number of times the section
      will loop.</TD
></TR
><TR
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>show</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>boolean</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
>No</TD
><TD
WIDTH="20%"
ALIGN="CENTER"
VALIGN="MIDDLE"
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
><TT
CLASS="constant"
>TRUE</TT
></I
></SPAN
></TD
><TD
WIDTH="20%"
ALIGN="LEFT"
VALIGN="MIDDLE"
>determines whether or not to show this section</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
><P
></P
><UL
><LI
><P
>&#13;   Required attributes are <TT
CLASS="parameter"
><I
>name</I
></TT
> and <TT
CLASS="parameter"
><I
>loop</I
></TT
>.
   </P
></LI
><LI
><P
>&#13;    The <TT
CLASS="parameter"
><I
>name</I
></TT
> of the <TT
CLASS="varname"
>{section}</TT
> can be
    anything you like,  made up of letters,  numbers and underscores, like
    <A
HREF="http://php.net/language.variables"
TARGET="_top"
>PHP variables</A
>.
    </P
></LI
><LI
><P
>&#13;    Sections can be nested, and the nested
   <TT
CLASS="varname"
>{section}</TT
> names must be unique from each other.
   </P
></LI
><LI
><P
>&#13;   The <TT
CLASS="parameter"
><I
>loop</I
></TT
> attribute,
   usually an array of values, determines the number of times the
   <TT
CLASS="varname"
>{section}</TT
> will loop.
   </P
></LI
><LI
><P
>When printing a variable within a <TT
CLASS="varname"
>{section}</TT
>, the
   <TT
CLASS="varname"
>{section}</TT
> <TT
CLASS="parameter"
><I
>name</I
></TT
> must be given next
   to variable name within [brackets].
   </P
></LI
><LI
><P
>&#13;   <TT
CLASS="varname"
>{sectionelse}</TT
> is
   executed when there are no values in the loop variable.
 	</P
></LI
><LI
><P
>&#13;  A <TT
CLASS="varname"
>{section}</TT
> also has its own variables that handle
  <TT
CLASS="varname"
>{section}</TT
> properties.
  These properties are accessible as: <A
HREF="language.variables.smarty.html#language.variables.smarty.loops"
>&#13;  <TT
CLASS="parameter"
><I
>{$smarty.section.name.property}</I
></TT
></A
>
  where <SPAN
CLASS="QUOTE"
>"name"</SPAN
> is the attribute <TT
CLASS="parameter"
><I
>name</I
></TT
>.
  </P
></LI
><LI
><P
>&#13;  <TT
CLASS="varname"
>{section}</TT
> properties are
  <A
HREF="language.function.section.html#section.property.index"
><TT
CLASS="parameter"
><I
>index</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.index.prev"
><TT
CLASS="parameter"
><I
>index_prev</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.index.next"
><TT
CLASS="parameter"
><I
>index_next</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.iteration"
><TT
CLASS="parameter"
><I
>iteration</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.first"
><TT
CLASS="parameter"
><I
>first</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.last"
><TT
CLASS="parameter"
><I
>last</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.rownum"
><TT
CLASS="parameter"
><I
>rownum</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.loop"
><TT
CLASS="parameter"
><I
>loop</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.show"
><TT
CLASS="parameter"
><I
>show</I
></TT
></A
>,
  <A
HREF="language.function.section.html#section.property.total"
><TT
CLASS="parameter"
><I
>total</I
></TT
></A
>.
  </P
></LI
></UL
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2438"
></A
><P
><B
>Example 7-30. Looping a simple array with {section}</B
></P
><P
><A
HREF="api.assign.html"
>assign()</A
> an array to Smarty from the php script</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1000</span><span style="color: #007700">,</span><span style="color: #0000BB">1001</span><span style="color: #007700">,</span><span style="color: #0000BB">1002</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'custid'</span><span style="color: #007700">,</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>The template that outputs the array</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{* this example will print out all the values of the $custid array *}
{section name=customer loop=$custid}
  id: {$custid[customer]}&#60;br /&#62;
{/section}
&#60;hr /&#62;
{*  print out all the values of the $custid array reversed *}
{section name=foo loop=$custid step=-1}
  {$custid[foo]}&#60;br /&#62;
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>id: 1000&#60;br /&#62;
id: 1001&#60;br /&#62;
id: 1002&#60;br /&#62;
&#60;hr /&#62;
id: 1002&#60;br /&#62;
id: 1001&#60;br /&#62;
id: 1000&#60;br /&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2447"
></A
><P
><B
>Example 7-31. {section} without an assigned array</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=foo start=10 loop=20 step=2}
  {$smarty.section.foo.index}
{/section}
&#60;hr /&#62;
{section name=bar loop=21 max=6 step=-2}
  {$smarty.section.bar.index}
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;  The above example will output:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>10 12 14 16 18
&#60;hr /&#62;
20 18 16 14 12 10</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2452"
></A
><P
><B
>Example 7-32. Naming a {section}</B
></P
><P
>The <TT
CLASS="parameter"
><I
>name</I
></TT
> of the <TT
CLASS="varname"
>{section}</TT
> can be anything
  you like, see <A
HREF="http://php.net/language.variables"
TARGET="_top"
>PHP variables</A
>.
  It is used to reference the data within the <TT
CLASS="varname"
>{section}</TT
>.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=anything loop=$myArray}
  {$myArray[anything].foo}
  {$name[anything]}
  {$address[anything].bar}
{/section}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2460"
></A
><P
><B
>Example 7-33. Looping an associative array's with {section}</B
></P
><P
>This is an example of printing an associative array
   of data within a <TT
CLASS="varname"
>{section}</TT
>. Following is the php script to assign the
   <TT
CLASS="parameter"
><I
>$contacts</I
></TT
> array to Smarty.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'John&nbsp;Smith'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'home'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'555-555-5555'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cell'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'666-555-5555'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'email'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'john@myexample.com'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Jack&nbsp;Jones'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'home'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'777-555-5555'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cell'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'888-555-5555'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'email'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'jack@myexample.com'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Jane&nbsp;Munson'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'home'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'000-555-5555'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cell'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'123456'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'email'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'jane@myexample.com'</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'contacts'</span><span style="color: #007700">,</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>The template to output <TT
CLASS="parameter"
><I
>$contacts</I
></TT
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$contacts}
&#60;p&#62;
  name: {$contacts[customer].name}&#60;br /&#62;
  home: {$contacts[customer].home}&#60;br /&#62;
  cell: {$contacts[customer].cell}&#60;br /&#62;
  e-mail: {$contacts[customer].email}
&#60;/p&#62;
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>&#60;p&#62;
  name: John Smith&#60;br /&#62;
  home: 555-555-5555&#60;br /&#62;
  cell: 666-555-5555&#60;br /&#62;
  e-mail: john@myexample.com
&#60;/p&#62;
&#60;p&#62;
  name: Jack Jones&#60;br /&#62;
  home phone: 777-555-5555&#60;br /&#62;
  cell phone: 888-555-5555&#60;br /&#62;
  e-mail: jack@myexample.com
&#60;/p&#62;
&#60;p&#62;
  name: Jane Munson&#60;br /&#62;
  home phone: 000-555-5555&#60;br /&#62;
  cell phone: 123456&#60;br /&#62;
  e-mail: jane@myexample.com
&#60;/p&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2471"
></A
><P
><B
>Example 7-34. {section} demonstrating the <TT
CLASS="varname"
>loop</TT
> variable</B
></P
><P
>This example assumes that <TT
CLASS="parameter"
><I
>$custid</I
></TT
>, <TT
CLASS="parameter"
><I
>$name</I
></TT
>
  and <TT
CLASS="parameter"
><I
>$address</I
></TT
> are all
  arrays containing the same number of values. First the php script that assign's the
  arrays to Smarty.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$id&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1001</span><span style="color: #007700">,</span><span style="color: #0000BB">1002</span><span style="color: #007700">,</span><span style="color: #0000BB">1003</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'custid'</span><span style="color: #007700">,</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fullnames&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'John&nbsp;Smith'</span><span style="color: #007700">,</span><span style="color: #DD0000">'Jack&nbsp;Jones'</span><span style="color: #007700">,</span><span style="color: #DD0000">'Jane&nbsp;Munson'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">,</span><span style="color: #0000BB">$fullnames</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$addr&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'253&nbsp;Abbey&nbsp;road'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'417&nbsp;Mulberry&nbsp;ln'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'5605&nbsp;apple&nbsp;st'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'address'</span><span style="color: #007700">,</span><span style="color: #0000BB">$addr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>The <TT
CLASS="parameter"
><I
>loop</I
></TT
> variable only determines the number of times to loop.
  You can access ANY variable from the template within the <TT
CLASS="varname"
>{section}</TT
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$custid}
&#60;p&#62;
  id: {$custid[customer]}&#60;br /&#62;
  name: {$name[customer]}&#60;br /&#62;
  address: {$address[customer]}
&#60;/p&#62;
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>&#60;p&#62;
  id: 1000&#60;br /&#62;
  name: John Smith&#60;br /&#62;
  address: 253 Abbey road
&#60;/p&#62;
&#60;p&#62;
  id: 1001&#60;br /&#62;
  name: Jack Jones&#60;br /&#62;
  address: 417 Mulberry ln
&#60;/p&#62;
&#60;p&#62;
  id: 1002&#60;br /&#62;
  name: Jane Munson&#60;br /&#62;
  address: 5605 apple st
&#60;/p&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2485"
></A
><P
><B
>Example 7-35. Nested {section}'s</B
></P
><P
>&#13;  Sections can be nested as deep as you like. With nested sections,
  you can access complex data structures, such as multi-dimensional
  arrays. This is a php script thats assign's the arrays.
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$id&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1001</span><span style="color: #007700">,</span><span style="color: #0000BB">1002</span><span style="color: #007700">,</span><span style="color: #0000BB">1003</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'custid'</span><span style="color: #007700">,</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fullnames&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'John&nbsp;Smith'</span><span style="color: #007700">,</span><span style="color: #DD0000">'Jack&nbsp;Jones'</span><span style="color: #007700">,</span><span style="color: #DD0000">'Jane&nbsp;Munson'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">,</span><span style="color: #0000BB">$fullnames</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$addr&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'253&nbsp;N&nbsp;45th'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'417&nbsp;Mulberry&nbsp;ln'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'5605&nbsp;apple&nbsp;st'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'address'</span><span style="color: #007700">,</span><span style="color: #0000BB">$addr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$types&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&nbsp;</span><span style="color: #DD0000">'home&nbsp;phone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'cell&nbsp;phone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'e-mail'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&nbsp;</span><span style="color: #DD0000">'home&nbsp;phone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'web'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&nbsp;</span><span style="color: #DD0000">'cell&nbsp;phone'</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'contact_type'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$types</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'555-555-5555'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'666-555-5555'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'john@myexample.com'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&nbsp;</span><span style="color: #DD0000">'123-456-4'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'www.example.com'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(&nbsp;</span><span style="color: #DD0000">'0457878'</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'contact_info'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>In this template, <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>$contact_type[customer]</I
></SPAN
> is an array of
  contact types for the current customer.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$custid}
&#60;hr&#62;
  id: {$custid[customer]}&#60;br /&#62;
  name: {$name[customer]}&#60;br /&#62;
  address: {$address[customer]}&#60;br /&#62;
  {section name=contact loop=$contact_type[customer]}
    {$contact_type[customer][contact]}: {$contact_info[customer][contact]}&#60;br /&#62;
  {/section}
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>&#60;hr&#62;
  id: 1000&#60;br /&#62;
  name: John Smith&#60;br /&#62;
  address: 253 N 45th&#60;br /&#62;
    home phone: 555-555-5555&#60;br /&#62;
    cell phone: 666-555-5555&#60;br /&#62;
    e-mail: john@myexample.com&#60;br /&#62;
&#60;hr&#62;
  id: 1001&#60;br /&#62;
  name: Jack Jones&#60;br /&#62;
  address: 417 Mulberry ln&#60;br /&#62;
    home phone: 123-456-4&#60;br /&#62;
    web: www.example.com&#60;br /&#62;
&#60;hr&#62;
  id: 1002&#60;br /&#62;
  name: Jane Munson&#60;br /&#62;
  address: 5605 apple st&#60;br /&#62;
    cell phone: 0457878&#60;br /&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2494"
></A
><P
><B
>Example 7-36. Database example with a {sectionelse}</B
></P
><P
>Results of a database search (eg ADODB or PEAR) are assigned to Smarty</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'select&nbsp;id,&nbsp;name,&nbsp;home,&nbsp;cell,&nbsp;email&nbsp;from&nbsp;contacts&nbsp;'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">.</span><span style="color: #DD0000">"where&nbsp;name&nbsp;like&nbsp;'$foo%'&nbsp;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'contacts'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAll</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>The template to output the database result in a HTML table</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>&#60;table&#62;
&#60;tr&#62;&#60;th&#62;&#38;nbsp;&#60;/th&#62;&#60;th&#62;Name&#62;&#60;/th&#62;&#60;th&#62;Home&#60;/th&#62;&#60;th&#62;Cell&#60;/th&#62;&#60;th&#62;Email&#60;/th&#62;&#60;/tr&#62;
{section name=co loop=$contacts}
  &#60;tr&#62;
    &#60;td&#62;&#60;a href="view.php?id={$contacts[co].id}"&#62;view&#60;a&#62;&#60;/td&#62;
    &#60;td&#62;{$contacts[co].name}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].home}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].cell}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].email}&#60;/td&#62;
  &#60;tr&#62;
{sectionelse}
  &#60;tr&#62;&#60;td colspan="5"&#62;No items found&#60;/td&#62;&#60;/tr&#62;
{/section}
&#60;/table&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.index"
></A
>.index</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>index</I
></TT
> contains the current array index, starting with zero
   or the <TT
CLASS="parameter"
><I
>start</I
></TT
> attribute if given It increments by one or by
   the <TT
CLASS="parameter"
><I
>step</I
></TT
> attribute if given.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Technical Note: </B
>
    If the <TT
CLASS="parameter"
><I
>step</I
></TT
> and <TT
CLASS="parameter"
><I
>start</I
></TT
>
     properties are not
    modified, then this works the same as the <A
HREF="language.function.section.html#section.property.iteration"
><TT
CLASS="parameter"
><I
>iteration</I
></TT
></A
>
    property, except it starts at zero instead of one.
   </P
></BLOCKQUOTE
></DIV
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2513"
></A
><P
><B
>Example 7-37. {section} <TT
CLASS="varname"
>index</TT
> property</B
></P
><P
>&#13;<DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>FYI: </B
><TT
CLASS="parameter"
><I
>$custid[customer.index]</I
></TT
> and <TT
CLASS="varname"
>$custid[customer]</TT
>
 are identical in meaning.</P
></BLOCKQUOTE
></DIV
>
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$custid}
  {$smarty.section.customer.index} id: {$custid[customer]}&#60;br /&#62;
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>0 id: 1000&#60;br /&#62;
1 id: 1001&#60;br /&#62;
2 id: 1002&#60;br /&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.index.prev"
></A
>.index_prev</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>index_prev</I
></TT
> is the previous loop index.
   On the first loop, this is set to -1.
  </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.index.next"
></A
>.index_next</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>index_next</I
></TT
> is  the next loop index. On the last
   loop, this is still one more than the current index, respecting the
   setting of the <TT
CLASS="parameter"
><I
>step</I
></TT
> attribute, if given.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2534"
></A
><P
><B
>Example 7-38. <TT
CLASS="varname"
>index</TT
>, <TT
CLASS="varname"
>index_next</TT
>
 and <TT
CLASS="varname"
>index_prev</TT
> properties </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1001</span><span style="color: #007700">,</span><span style="color: #0000BB">1002</span><span style="color: #007700">,</span><span style="color: #0000BB">1003</span><span style="color: #007700">,</span><span style="color: #0000BB">1004</span><span style="color: #007700">,</span><span style="color: #0000BB">1005</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'rows'</span><span style="color: #007700">,</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>Template to output the above array in a table</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{* $rows[row.index] and $rows[row] are identical in meaning *}
&#60;table&#62;
  &#60;tr&#62;
    &#60;th&#62;index&#60;/th&#62;&#60;th&#62;id&#60;/th&#62;
    &#60;th&#62;index_prev&#60;/th&#62;&#60;th&#62;prev_id&#60;/th&#62;
    &#60;th&#62;index_next&#60;/th&#62;&#60;th&#62;next_id&#60;/th&#62;
  &#60;/tr&#62;
{section name=row loop=$rows}
  &#60;tr&#62;
    &#60;td&#62;{$smarty.section.row.index}&#60;/td&#62;&#60;td&#62;{$rows[row]}&#60;/td&#62;
    &#60;td&#62;{$smarty.section.row.index_prev}&#60;/td&#62;&#60;td&#62;{$rows[row.index_prev]}&#60;/td&#62;
    &#60;td&#62;{$smarty.section.row.index_next}&#60;/td&#62;&#60;td&#62;{$rows[row.index_next]}&#60;/td&#62;
  &#60;/tr&#62;
{/section}
&#60;/table&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13; The above example will output a table containing the  following:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><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
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.iteration"
></A
>.iteration</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>iteration</I
></TT
> contains the current loop iteration and starts at one.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
    This is not affected by the <TT
CLASS="varname"
>{section}</TT
> properties
    <TT
CLASS="parameter"
><I
>start</I
></TT
>, <TT
CLASS="parameter"
><I
>step</I
></TT
> and <TT
CLASS="parameter"
><I
>max</I
></TT
>,
     unlike the <A
HREF="language.function.section.html#section.property.index"
><TT
CLASS="parameter"
><I
>index</I
></TT
></A
>
    property. <TT
CLASS="parameter"
><I
>iteration</I
></TT
> also starts with one instead of zero
    unlike <TT
CLASS="parameter"
><I
>index</I
></TT
>. <A
HREF="language.function.section.html#section.property.rownum"
><TT
CLASS="parameter"
><I
>rownum</I
></TT
></A
> is an alias to
    <TT
CLASS="parameter"
><I
>iteration</I
></TT
>,  they are identical.
   </P
></BLOCKQUOTE
></DIV
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2561"
></A
><P
><B
>Example 7-39. A section's <TT
CLASS="varname"
>iteration</TT
> property </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;array&nbsp;of&nbsp;3000&nbsp;to&nbsp;3015<br /></span><span style="color: #0000BB">$id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">3000</span><span style="color: #007700">,</span><span style="color: #0000BB">3015</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'arr'</span><span style="color: #007700">,</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>Template to output every other element of the <TT
CLASS="varname"
>$arr</TT
>
array as <TT
CLASS="varname"
>step</TT
>=2</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><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]}&#60;br /&#62;
{/section}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>iteration=1 index=5 id=3005&#60;br /&#62;
iteration=2 index=7 id=3007&#60;br /&#62;
iteration=3 index=9 id=3009&#60;br /&#62;
iteration=4 index=11 id=3011&#60;br /&#62;
iteration=5 index=13 id=3013&#60;br /&#62;
iteration=6 index=15 id=3015&#60;br /&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13;   Another example uses the <TT
CLASS="parameter"
><I
>iteration</I
></TT
> property to
   output a table header block every five rows and
   uses <A
HREF="language.function.if.html"
><TT
CLASS="varname"
>{if}</TT
></A
>
   with the mod operator.
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>&#60;table&#62;
{section name=co loop=$contacts}
  {if $smarty.section.co.iteration % 5 == 1}
    &#60;tr&#62;&#60;th&#62;&#38;nbsp;&#60;/th&#62;&#60;th&#62;Name&#62;&#60;/th&#62;&#60;th&#62;Home&#60;/th&#62;&#60;th&#62;Cell&#60;/th&#62;&#60;th&#62;Email&#60;/th&#62;&#60;/tr&#62;
  {/if}
  &#60;tr&#62;
    &#60;td&#62;&#60;a href="view.php?id={$contacts[co].id}"&#62;view&#60;a&#62;&#60;/td&#62;
    &#60;td&#62;{$contacts[co].name}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].home}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].cell}&#60;/td&#62;
    &#60;td&#62;{$contacts[co].email}&#60;/td&#62;
  &#60;tr&#62;
{/section}
&#60;/table&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.first"
></A
>.first</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>first</I
></TT
> is set to <TT
CLASS="constant"
>TRUE</TT
> if the current <TT
CLASS="varname"
>{section}</TT
>
   iteration is the initial one.
  </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.last"
></A
>.last</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>last</I
></TT
> is set to <TT
CLASS="constant"
>TRUE</TT
>
   if the current section iteration is the final one.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2587"
></A
><P
><B
>Example 7-40. {section} property <TT
CLASS="varname"
>first</TT
> and <TT
CLASS="varname"
>last</TT
></B
></P
><P
>&#13;   This example loops the <TT
CLASS="varname"
>$customers</TT
> array,
   outputs a header block on the first iteration and
   on the last outputs the footer block. Also uses the
   <A
HREF="language.function.section.html#section.property.total"
><TT
CLASS="parameter"
><I
>total</I
></TT
></A
> property.
   </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$customers}
  {if $smarty.section.customer.first}
    &#60;table&#62;
    &#60;tr&#62;&#60;th&#62;id&#60;/th&#62;&#60;th&#62;customer&#60;/th&#62;&#60;/tr&#62;
  {/if}

  &#60;tr&#62;
    &#60;td&#62;{$customers[customer].id}}&#60;/td&#62;
    &#60;td&#62;{$customers[customer].name}&#60;/td&#62;
  &#60;/tr&#62;

  {if $smarty.section.customer.last}
    &#60;tr&#62;&#60;td&#62;&#60;/td&#62;&#60;td&#62;{$smarty.section.customer.total} customers&#60;/td&#62;&#60;/tr&#62;
    &#60;/table&#62;
  {/if}
{/section}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.rownum"
></A
>.rownum</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>rownum</I
></TT
> contains the current loop iteration,
   starting with one. It is an alias to <A
HREF="language.function.section.html#section.property.iteration"
><TT
CLASS="parameter"
><I
>iteration</I
></TT
></A
>,
   they work identically.
  </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.loop"
></A
>.loop</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>loop</I
></TT
> contains the last index number
   that this {section}
   looped. This can be used inside or after the <TT
CLASS="varname"
>{section}</TT
>.
     </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2607"
></A
><P
><B
>Example 7-41. {section} property <TT
CLASS="varname"
>loop</TT
>s</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$custid}
  {$smarty.section.customer.index} id: {$custid[customer]}&#60;br /&#62;
{/section}
There are {$smarty.section.customer.loop} customers shown above.</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>0 id: 1000&#60;br /&#62;
1 id: 1001&#60;br /&#62;
2 id: 1002&#60;br /&#62;
There are 3 customers shown above.</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.show"
></A
>.show</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>show</I
></TT
> is used as a parameter to section.
   <TT
CLASS="parameter"
><I
>show</I
></TT
> is a boolean value, <TT
CLASS="constant"
>TRUE</TT
> or <TT
CLASS="constant"
>FALSE</TT
>. If
   <TT
CLASS="constant"
>FALSE</TT
>, the section will not be displayed. If there is a
   <TT
CLASS="varname"
>{sectionelse}</TT
>  present, that will be alternately displayed.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2622"
></A
><P
><B
>Example 7-42. <TT
CLASS="varname"
>show</TT
> property </B
></P
><P
>Boolean <TT
CLASS="varname"
>$show_customer_info</TT
> has been passed from the PHP
  application, to regulate whether or not this section shows.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$customers show=$show_customer_info}
  {$smarty.section.customer.rownum} id: {$customers[customer]}&#60;br /&#62;
{/section}

{if $smarty.section.customer.show}
  the section was shown.
{else}
  the section was not shown.
{/if}</PRE
></TD
></TR
></TABLE
><P
>&#13;   The above example will output:
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>1 id: 1000&#60;br /&#62;
2 id: 1001&#60;br /&#62;
3 id: 1002&#60;br /&#62;

the section was shown.</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="section.property.total"
></A
>.total</H2
><P
>&#13;   <TT
CLASS="parameter"
><I
>total</I
></TT
> contains the number of iterations that this
   <TT
CLASS="varname"
>{section}</TT
> will loop. This can be used inside or after a
   <TT
CLASS="varname"
>{section}</TT
>.
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN2636"
></A
><P
><B
>Example 7-43. <TT
CLASS="varname"
>total</TT
> property example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{section name=customer loop=$custid step=2}
  {$smarty.section.customer.index} id: {$custid[customer]}&#60;br /&#62;
{/section}
   There are {$smarty.section.customer.total} customers shown above.</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;   See also <A
HREF="language.function.foreach.html"
><TT
CLASS="varname"
>{foreach}</TT
></A
>
   and
   <A
HREF="language.variables.smarty.html#language.variables.smarty.loops"
><TT
CLASS="parameter"
><I
>$smarty.section</I
></TT
></A
>.
  </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="language.function.php.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="language.function.strip.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>{php}</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="language.builtin.functions.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>{strip}</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>