<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="language.function.php.html" accesskey="P">Prev</a></td> <td width="50%" align="center" valign="bottom">Chapter 7. Built-in Functions[第七章.内建函数]</td> <td width="25%" align="right" valign="bottom"><a href="language.function.while.html" accesskey="N">Next</a></td></tr></table>
# {section},{sectionelse}遍历数组
**Table of Contents目录**[.index](#)[.index_prev](#)[.index_next](#)[.iteration](#)[.first](#)[.last](#)[.rownum](#)[.loop](#)[.show](#)[.total](#)
A {section} is for looping over sequentially indexed arrays of data, unlike {foreach} which is used to loop over a single associative array. Every {section} tag must be paired with a closing {/section} tag.
不同于{foreach}遍历单层关联数组,{section}支持循序索引遍历数组中的数据(支持一次性读取多维数组)。每个{section}标签必须与闭合标签{/section}成对出现。
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> The {foreach} loop can do everything a {section} loop can do, and has a simpler and easier syntax. It is usually preferred over the {section} loop.<br/> {foreach}可以做{section}能做的所有事,而且语法更简单、更容易。它通常是循环数组的首选。</td> </tr></table>
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> {section} loops cannot loop over associative arrays, they must be numerically indexed, and sequential (0,1,2,...). For associative arrays, use the {foreach} loop. <br/> {section}循环不能遍历关联数组,(被循环的)数组必须是数字索引,像这样(0,1,2,...)。对于关联数组,请用{foreach}循环。</td> </tr></table>
**Attribute:**
| Attribute Name | Type | Required | Default | Description |
|-----|-----|-----|-----|-----|
| name | string | Yes | *n/a* | The name of the section |
| loop | [$variable_name] | Yes | *n/a* | The name of the variable to determine # of loop iterations |
| start | integer | No | *0* | 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. |
| step | integer | No | *1* | 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. |
| max | integer | No | *1* | Sets the maximum number of times the section will loop. |
| show | boolean | No | *true* | determines whether or not to show this section |
**Option Flags:**
| **Name** | **Description** |
|-----|-----|
| nocache | Disables caching of the {section} loop |
**属性:**
| 属性 | 类型 | 是否必须 | 缺省值 | 描述 |
|-----|-----|-----|-----|-----|
| name | string | Yes | *n/a* | 该循环的名称 |
| loop | [$variable_name] | Yes | *n/a* | 决定循环次数的变量名称 |
| start | integer | No | *0* | 循环执行的初始位置. 如果该值为负数,开始位置从数组的尾部算起. 例如:如果数组中有7个元素,指定start为-2,那么指向当前数组的索引为5. 非法值(超过了循环数组的下限)将被自动调整为最接近的合法值. |
| step | integer | No | *1* | 该值决定循环的步长. 例如指定step=2将只遍历下标为0、2、4等的元素. 如果step为负值,那么遍历数组的时候从后向前遍历. |
| max | integer | No | *1* | 设定循环最大执行次数. |
| show | boolean | No | *true* | 决定是否显示该循环. |
**选项标记:**
| **名称** | **描述** |
|-----|-----|
| nocache | {section} 循环禁用缓存 |
* Required attributes are name and loop.
* The name of the {section} can be anything you like, made up of letters, numbers and underscores,like PHP variables [http://php.net/language.variables].
* {section}'s can be nested, and the nested {section} names must be unique from each other.
* The loop attribute, usually an array of values, determines the number of times the {section} will loop. You can also pass an integer as the loop value.
* When printing a variable within a {section}, the {section} name must be given next to variable name within [brackets].
* {sectionelse} is executed when there are no values in the loop variable.
* A {section} also has its own variables that handle {section} properties. These properties are accessible as: {$smarty.section.name.property} where “name” is the attribute name.
* {section} properties are index, index_prev, index_next, iteration, first, last,rownum, loop, show, total.
必须设置*name*和*loop*属性;
{section}的名称可以是你喜欢的任何字母、下划线、数字组合,与php变量(命名)相同;
{section}可以嵌套,但必须确保嵌套的{section}名称唯一;
*loop*属性通常是一个数组值,它决定{section}循环的次数。你也可以为loop提供一个具体的整数值;
当需要在{section}内输出一个变量时,{section}的变量名必须用方括号括起并挨在该输出变量名的右边(译注:如$abc[mysection]);
当循环变量无值时执行{sectionelse};
{section}同样有自己的变量处理{section}属性,可以通过调用{$smarty.section.name.property}访问这些属性,这里‘name’是个变量名;
{section}的属性有index、index_prev、index_next、iteration、first、last、rownum、loop、show、total。
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"><a name="AEN2760" id="AEN2760"/> <b><span class="PROGRAMLISTING">Example 7.60. Looping a simple array with {section}</span><br/> 例 7-60. 一个简单{section}循环演示 </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="PROGRAMLISTING">assign() an array to Smarty<?php$data = array(1000,1001,1002);$smarty->assign('custid',$data);?>
The template that outputs the array{* this example will print out all the values of the $custid array *}{section name=customer loop=$custid}{section customer $custid} {* short-hand *} id: {$custid[customer]}<br />{/section}<hr />{* print out all the values of the $custid array reversed *}反向输出{section name=foo loop=$custid step=-1}{section foo $custid step=-1} {* short-hand *} {$custid[foo]}<br />{/section}
The above example will output:id: 1000<br />id: 1001<br />id: 1002<br /><hr />id: 1002<br />id: 1001<br />id: 1000<br /></pre></td></tr></table></div></td></tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.61. {section} without an assigned array<br/> 例 7-61.未分配数组的{section}演示 </b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> {section name=foo start=10 loop=20 step=2}<br/>{$smarty.section.foo.index}<br/>{/section}<br/><hr /><br/>{section name=bar loop=21 max=6 step=-2}<br/>{$smarty.section.bar.index}<br/>{/section}<br/>The above example will output:<br/><br/>10 12 14 16 18<br/><hr /><br/>20 18 16 14 12 10</td></tr></table></div></td></tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.62. Naming a {section}<br/> 例 7-62. {section}名称演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> The name of the {section} can be anything you like, see PHP variables [http://php.net/ language.variables]. It is used to reference the data within the {section}.<br/> {section name=anything loop=$myArray}<br/>{$myArray[anything].foo}<br/>{$name[anything]}<br/>{$address[anything].bar}<br/>{/section}</td></tr></table></div></td></tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.63. Looping an associative array with {section}<br/> 例 7-63. 用{section}循环关联数组的演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <p>This is an example of printing an associative array of data with a {section}. Following is the php script to assign the $contacts array to Smarty.<br/><br/> <?php<br/> $data = array(<br/> array('name' => 'John Smith', 'home' => '555-555-5555',<br/> 'cell' => '666-555-5555', 'email' => 'john@myexample.com'),<br/> array('name' => 'Jack Jones', 'home' => '777-555-5555',<br/> 'cell' => '888-555-5555', 'email' => 'jack@myexample.com'),<br/> array('name' => 'Jane Munson', 'home' => '000-555-5555',<br/> 'cell' => '123456', 'email' => 'jane@myexample.com')<br/> );<br/> $smarty->assign('contacts',$data);<br/> ?><br/><br/> The template to output $contacts<br/> {section name=customer loop=$contacts}<br/> <p><br/> name: {$contacts[customer].name}<br /><br/> home: {$contacts[customer].home}<br /><br/> cell: {$contacts[customer].cell}<br /><br/> e-mail: {$contacts[customer].email}<br/> </p><br/> {/section}</p> <p> <br/> The above example will output:<br/> <p><br/>name: John Smith<br /><br/>home: 555-555-5555<br /><br/>cell: 666-555-5555<br /><br/>e-mail: john@myexample.com<br/></p><br/><p><br/>name: Jack Jones<br /><br/>home phone: 777-555-5555<br /><br/>cell phone: 888-555-5555<br /><br/>e-mail: jack@myexample.com<br/></p><br/><p><br/>name: Jane Munson<br /><br/>home phone: 000-555-5555<br /><br/>cell phone: 123456<br /><br/>e-mail: jane@myexample.com<br/></p></p></td></tr></table></div></td></tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.64. {section} demonstrating the loop variable<br/> 例 7-64. 演示{section}循环变量</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <p>This example assumes假设 that $custid, $name and $address are all arrays containing the same number个数 of values. First the php script that assign's the arrays to Smarty.<br/> <?php<br/> $id = array(1001,1002,1003);<br/> $smarty->assign('custid',$id);<br/> $fullnames = array('John Smith','Jack Jones','Jane Munson');<br/> $smarty->assign('name',$fullnames);<br/> $addr = array('253 Abbey road', '417 Mulberry ln', '5605 apple st');<br/> $smarty->assign('address',$addr);<br/> ?><br/> The loop variable only determines the number of times to loop. You can access ANY variable from the template within the {section}. This is useful for looping multiple arrays. You can pass an array which will determine the loop count by the array size, or you can pass an integer to specify the number of loops.</p> <p>loop变量只决定循环的次数,你可以访问模版{section}中的任何变量,这个特性在多维数组中非常有用。你可以传递一个数组,该数组的大小决定循环间隔,或者您也可以通过一个整数来指定循环次数。</p> <p>{section name=customer loop=$custid}<br/> <p><br/>id: {$custid[customer]}<br /><br/>name: {$name[customer]}<br /><br/>address: {$address[customer]}<br/></p><br/>{/section}<br/><br/>The above example will output:<br/><p><br/>id: 1000<br /><br/>name: John Smith<br /><br/>address: 253 Abbey road<br/></p><br/><p><br/>id: 1001<br /><br/>name: Jack Jones<br /><br/>address: 417 Mulberry ln<br/></p><br/><p><br/>id: 1002<br /><br/>name: Jane Munson<br /><br/>address: 5605 apple st<br/></p></p></td></tr></table></div></td></tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.65. Nested {section}'s<br/> 例 7-65. {section}嵌套 演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <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 .php script thats assign's the arrays.</p> <p>{section}可以无限嵌套,在嵌套{section}里,你可以访问复杂的数据结构,如多维数组。<br/> <?php<br/> $id = array(1001,1002,1003);<br/> $smarty->assign('custid',$id);<br/> $fullnames = array('John Smith','Jack Jones','Jane Munson');<br/> $smarty->assign('name',$fullnames);<br/> $addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');<br/> $smarty->assign('address',$addr);<br/> $types = array(<br/> array( 'home phone', 'cell phone', 'e-mail'),<br/> array( 'home phone', 'web'),<br/> array( 'cell phone')<br/> );<br/> $smarty->assign('contact_type', $types);<br/> $info = array(<br/> array('555-555-5555', '666-555-5555', 'john@myexample.com'),<br/> array( '123-456-4', 'www.example.com'),<br/> array( '0457878')<br/> );<br/> $smarty->assign('contact_info', $info);<br/> ?><br/><br/> In this template, $contact_type[customer] is an array of contact types for the current customer.<br/> 在这个例子里面,$contact_type[customer]是当前customer的连联类型数组。<br/><br/> {section name=customer loop=$custid}<br/> <hr><br/> id: {$custid[customer]}<br /><br/> name: {$name[customer]}<br /><br/> address: {$address[customer]}<br /><br/> {section name=contact loop=$contact_type[customer]}<br/> {$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br /><br/> {/section}<br/> {/section}<br/><br/> The above example will output:<br/> <hr><br/> id: 1000<br /><br/> name: John Smith<br /><br/> address: 253 N 45th<br /><br/> home phone: 555-555-5555<br /><br/> cell phone: 666-555-5555<br /><br/> e-mail: john@myexample.com<br /><br/> <hr><br/> id: 1001<br /><br/> name: Jack Jones<br /><br/> address: 417 Mulberry ln<br /><br/> home phone: 123-456-4<br /><br/> web: www.example.com<br /><br/> <hr><br/> id: 1002<br /><br/> name: Jane Munson<br /><br/> address: 5605 apple st<br /><br/> cell phone: 0457878<br /> </p> </td></tr></table></div></td></tr></table>
**Example 7.66. Database example with a {sectionelse}
例 7-66. {sectionelse}数据库演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Results of a database search (eg ADODB or PEAR) are assigned to Smarty<br/><br/> <?php<br/> $sql = 'select id, name, home, cell, email from contacts '<br/>."where name like '$foo%' ";<br/>$smarty->assign('contacts', $db->getAll($sql));<br/>?><br/>The template to output the database result in a HTML table<br/><table><br/><tr><th>&nbsp;</th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr><br/>{section name=co loop=$contacts}<br/><tr><br/><td><a href="view.php?id={$contacts[co].id}">view<a></td><br/><td>{$contacts[co].name}</td><br/><td>{$contacts[co].home}</td><br/><td>{$contacts[co].cell}</td><br/><td>{$contacts[co].email}</td><br/><tr><br/>{sectionelse}<br/><tr><td colspan="5">No items found</td></tr><br/>{/section}<br/></table></td> </tr></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. index包含当前数组的索引,以0开始,如果设置了start变量(属性)则以该数字开始。{section}循环一次索引自动向前1步,如果给出了step变量则以该步长向前。
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>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.<br/>如果没有修改step和start变量,则效果与iteration属性(见下文的<a href="#iteration">.iteration</a>)一样,除非后者以1开始,而不是0。</td> </tr></table>
**Example 7.67. {section} index property
例 7-67. {section}的index属性(变量)演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Note<br/> $custid[customer.index] and $custid[customer] are identical相同的.<br/> {section name=customer loop=$custid}<br/>{$smarty.section.customer.index} id: {$custid[customer]}<br /><br/>{/section}<br/><br/>The above example will output:<br/>0 id: 1000<br /><br/>1 id: 1001<br /><br/>2 id: 1002<br /></td> </tr></table>
.index_prev
index_prev is the previous loop index. On the first loop, this is set to -1.
index_prev为前一循环的索引值。 循环开始时,此值为-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.
index_next为下个循环的索引值。循环到最尾,此值仍然比当前索引值大1,如果设定了step,取决于该值。
**Example 7.68. index, index_next and index_prev properties
例 7-68. index、index_next和index_prev属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p><?php<br/> $data = array(1001,1002,1003,1004,1005);<br/> $smarty->assign('rows',$data);<br/> ?><br/> Template to output the above array in a table<br/> {* $rows[row.index] and $rows[row] are identical in meaning *}<br/> <table><br/> <tr><br/> <th>index</th><th>id</th><br/> <th>index_prev</th><th>prev_id</th><br/> <th>index_next</th><th>next_id</th><br/> </tr><br/> {section name=row loop=$rows}<br/> <tr><br/> <td>{$smarty.section.row.index}</td><td>{$rows[row]}</td><br/> <td>{$smarty.section.row.index_prev}</td><td>{$rows[row.index_prev]}</td><br/> <td>{$smarty.section.row.index_next}</td><td>{$rows[row.index_next]}</td><br/> </tr><br/> {/section}<br/> </table></p> <p>The above example will output a table containing the following:<br/> index id index_prev prev_id index_next next_id<br/> 0 1001 -1 1 1002<br/> 1 1002 0 1001 2 1003<br/> 2 1003 1 1002 3 1004<br/> 3 1004 2 1003 4 1005<br/> 4 1005 3 1004 5</p></td> </tr></table>
.iteration
iteration contains the current loop iteration and starts at one.
iteration包含当前的迭代循环,开始值为1。
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>This is not affected by the {section} properties start, step and max, unlike the index property. iteration also starts with one instead of zero unlike index. rownum is an alias to iteration, they are identical.<br/><p>.iteration不像.index属性受start、step和max属性的影响,该值总是从1开始(index是从0开始的)。.rownum是.iteration的别名,两者意思一样。</p><p> </p></td> </tr></table>
译注
| 本属性用来统计循环迭代多少次。 |
|-----|
**Example 7.69. A section's iteration property
例 7-69. {section}的iteration属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p><?php<br/> // array of 3000 to 3015<br/> $id = range(3000,3015);<br/> $smarty->assign('arr',$id);<br/> ?><br/> Template to output every other element of the $arr array as step=2<br/> {section name=cu loop=$arr start=5 step=2}<br/> iteration={$smarty.section.cu.iteration}<br/> index={$smarty.section.cu.index}<br/> id={$custid[cu]}<br /><br/> {/section}<br/> The above example will output:<br/> iteration=1 index=5 id=3005<br /><br/> iteration=2 index=7 id=3007<br /><br/> iteration=3 index=9 id=3009<br /><br/> iteration=4 index=11 id=3011<br /><br/> iteration=5 index=13 id=3013<br /><br/> iteration=6 index=15 id=3015<br /></p> <p> Another example that uses the iteration property to output a table header block every five rows.<br/><br/><table><br/> {section name=co loop=$contacts}<br/> {if $smarty.section.co.iteration is div by 5}<br/><tr><th>&nbsp;</th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr><br/> {/if}<br/><tr><br/><td><a href="view.php?id={$contacts[co].id}">view<a></td><br/><td>{$contacts[co].name}</td><br/><td>{$contacts[co].home}</td><br/><td>{$contacts[co].cell}</td><br/><td>{$contacts[co].email}</td><br/><tr><br/> {/section}<br/></table><br/> An that uses the iteration property to alternate a text color every third row.<br/><br/><table><br/> {section name=co loop=$contacts}<br/> {if $smarty.section.co.iteration is even by 3}<br/><span style="color: #ffffff">{$contacts[co].name}</span><br/> {else}<br/><span style="color: #dddddd">{$contacts[co].name}</span><br/> {/if}<br/> {/section}<br/></table><br/></p> </td> </tr></table>
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>The "is div by" syntax is a simpler alternative to the PHP mod operator syntax. The mod operator is allowed: {if $smarty.section.co.iteration % 5 == 1} will work just the same.<br/>is div by'语法是一个php模式语法的简单替代,在.iteration模式中允许:{if $smarty.section.co.iteration % 5 == 1} ,在效果上与前者是一样的。<p/></td> </tr></table>
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td><br/>Note<br/>You can also use "is odd by" to reverse the alternating. <br/>你也可以用'is odd by'倒序交替。</td> </tr></table>
.first
first is set to TRUE if the current {section} iteration is the initial one.
如果当前循环第一次执行,first被设置为true。
.last
last is set to TRUE if the current section iteration is the final one.
如果当前section迭代执行到最尾,last 被设置为true。
**Example 7.70. {section} property first and last
例 7-70. {section}的first和last属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> This example loops the $customers array, outputs a header block on the first iteration and on the last<br/> outputs the footer block. Also uses the total property.<br/> {section name=customer loop=$customers}<br/>{if $smarty.section.customer.first}<br/><table><br/><tr><th>id</th><th>customer</th></tr><br/>{/if}<br/><tr><br/><td>{$customers[customer].id}}</td><br/><td>{$customers[customer].name}</td><br/></tr><br/>{if $smarty.section.customer.last}<br/><tr><td></td><td>{$smarty.section.customer.total} customers</td></tr><br/></table><br/>{/if}<br/>{/section}</td> </tr></table>
.rownum
rownum contains the current loop iteration, starting with one. It is an alias to iteration, they work identically.
rownum包含当前循环迭代。从1开始。该属性是iteration的别名,两者是一样的。
.loop
loop contains the last index number that this {section} looped. This can be used inside or after the {section}.
loop包含{section}上次循环时的最后索引值, 该值可以用于循环内部或循环结束后。
**Example 7.71. {section} property loop
例 7-71. {section}loop属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p> {section name=customer loop=$custid}<br/> {$smarty.section.customer.index} id: {$custid[customer]}<br /><br/> {/section}<br/> There are {$smarty.section.customer.loop} customers shown above.<br/><br/> The above example will output:<br/> 0 id: 1000<br /><br/> 1 id: 1001<br /><br/> 2 id: 1002<br /><br/> There are 3 customers shown above.</p> <p/></td> </tr></table>
.show
show is used as a parameter to section and is a boolean value. If FALSE, the section will not be displayed.
If there is a {sectionelse} present, that will be alternately displayed.
*show*是section的参数,为布尔值,如果设置为 false,该循环将不显示。如果存在{sectionelse}子句,该字句将交替显示。
**Example 7.72. show property
例 7-72. {section}show属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Boolean $show_customer_info has been passed from the PHP application, to regulate whether or not this section shows.<br/> {section name=customer loop=$customers show=$show_customer_info}<br/>{$smarty.section.customer.rownum} id: {$customers[customer]}<br /><br/>{/section}<br/>{if $smarty.section.customer.show}<br/>the section was shown.<br/>{else}<br/>the section was not shown.<br/>{/if}<br/><br/>The above example will output:<br/>1 id: 1000<br /><br/>2 id: 1001<br /><br/>3 id: 1002<br /><br/>the section was shown.</td> </tr></table>
.total
total contains the number of iterations that this {section} will loop. This can be used inside or after a {section}.
total包含{section}循环执行总的次数,可以在{section}执行中/后调用此属性。
**Example 7.73. total property example
例 7-73. total属性演示**
<table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> {section name=customer loop=$custid step=2}<br/>{$smarty.section.customer.index} id: {$custid[customer]}<br /><br/>{/section}<br/>There are {$smarty.section.customer.total} customers shown above.<br/></td> </tr></table>
参见[{foreach}](#)、[{for}](#)和[$smarty.section](#)。
<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.while.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">{while}<br/> 循环</td></tr></table>
- Smarty模板编译引擎
- 序
- 译序
- I.开始
- 第一章. 什么是Smarty?
- 第二章. 安装
- II.模板设计者篇
- 第三章.基本语法
- 注释
- 变量
- 函数
- 属性
- 双引号里嵌入变量
- 数学运算
- 忽略Smarty解析
- 第四章.变量
- 从PHP分配的变量
- 从配置文件读取的变量
- 变量范围
- {$smarty}保留变量
- 第五章.变量调节器
- capitalize
- cat
- count_characters
- count_paragraphs
- count_sentences
- count_words
- date_format
- default
- escape
- indent
- lower
- nl2br
- regex_replace
- replace
- spacify
- string_format
- strip
- strip_tags
- truncate
- upper
- wordwrap
- 第六章.组合修改器
- 第七章.内置函数
- {$var=}
- {append}
- {assign}
- {block}
- {call}
- {capture}
- {config_load}
- {debug}
- {extends}
- {for}
- {foreach},{foreachelse}
- @index
- {function}
- {if},{elseif},{else}
- {include}
- {include_php}
- {insert}
- {ldelim},{rdelim}
- {literal}
- {nocache}
- {php}
- {section},{sectionelse}
- .index
- {while}
- 第八章.自定义函数
- {counter}
- {cycle}
- {eval}
- {fetch}
- {html_checkboxes}
- {html_image}
- {html_options}
- {html_radios}
- {html_select_date}
- {html_select_time}
- {html_table}
- {mailto}
- {math}
- {textformat}
- 第九章.配置文件
- 第十章.调试控制台
- III.模板程序员篇
- 第十一章 常量
- SMARTY_DIR
- 第十二章 Smarty类变量
- $template_dir
- 第十三章.Smarty类方法
- append()
- appendByRef()
- assign()
- assignByRef()
- clearAllAssign()
- clearAllCache()
- clearAssign()
- clearCache()
- clearCompiledTpl()
- clearConfig()
- compileAllConfig()
- compileAllTemplates()
- configLoad()
- createData()
- createTemplate()
- disableSecurity()
- display()
- enableSecurity()
- fetch()
- getConfigVars()
- getRegisteredObject()
- getTags()
- getTemplateVars()
- isCached()
- loadFilter()
- registerFilter()
- registerPlugin()
- registerObject()
- registerResource()
- templateExists()
- unregisterFilter()
- unregisterPlugin()
- unregisterObject()
- unregisterResource()
- testInstall()
- 第十四章.缓存
- 建立缓存
- 多重缓存
- 缓存集合
- 控制插件输出的可缓存性
- 第十五章.高级特性
- 安全
- 通过模板更改设置
- 模板继承
- 数据流
- 对象
- 静态类
- 预过滤器
- 后过滤器
- 输出过滤器
- 缓存处理函数
- 资源
- 第十六章.以插件扩展Smarty
- 插件如何工作
- 命名约定
- 编写插件
- 模板函数
- 调节器
- 块函数
- 编译函数
- 预滤器/后滤器
- 输出过滤器
- 资源
- 插入
- Ⅳ.附录
- 第十七章.疑难解答
- Smarty/PHP 错误
- 第十八章.使用技巧和经验
- 空白变量处理
- 默认变量处理
- 传递变量标题给头模板
- 日期
- WAP/WML
- 组件化模板
- 拒绝电子邮件地址
- 第十九章. 相关资源
- 第二十章. 漏洞
- 3.0安装包
- 2.x版本升级至3.x版本的提示
- 3.0.x使用指南
- 翻译人员列表