Files
smarty/docs/ru/designers/language-builtin-functions/language-function-section.xml
2005-12-05 17:11:58 +00:00

808 lines
20 KiB
XML

<?xml version="1.0" encoding="windows-1251"?>
<!-- $Revision$ -->
<!-- EN-Revision: 1.14 Maintainer: freespace Status: ready -->
<sect1 id="language.function.section">
<title>{section},{sectionelse}</title>
<para>
Ñåêöèè èñïîëüçóþòñÿ äëÿ îáõîäà
<emphasis role="bold">ìàññèâîâ äàííûõ</emphasis>
(òàê æå, êàê è <link linkend="language.function.foreach">{foreach}</link>).
Êàæäûé òåã <emphasis>{section}</emphasis> äîëæåí èìåòü ïàðó
<emphasis>{/section}</emphasis>. Îáÿçàòåëüíûìè ïàðàìåòðàìè ÿâëÿþòñÿ
<emphasis>name</emphasis> è <emphasis>loop</emphasis>. Èìÿ öèêëà
{section} ìîæåò áûòü ëþáûì, ñîñòîÿùèì èç áóêâ, öèôð è çíàêîâ
ïîä÷åðêèâàíèÿ. Öèêëû <emphasis>{section}</emphasis> ìîãóò áûòü âëîæåííûìè
è èìåíà âëîæåííûõ {section} äîëæíû áûòü óíèêàêëüíûìè ìåæäó ñîáîé.
Ïåðåìåííàÿ <emphasis>loop</emphasis> (îáû÷íî - ìàññèâ çíà÷åíèé)
îïðåäåëÿåò êîëè÷åñòâî èòåðàöèé öèêëà.
Ïðè ïå÷àòè ïåðåìåííûõ âíóòðè ñåêöèè, èìÿ ñåêöèè äîëæíî áûòü óêàçàíî
ðÿäîì ñ èìåíåì ïåðåìåííîé âíóòðè êâàäðàòíûõ ñêîáîê [].
<emphasis>{sectionelse}</emphasis> âûïîëíÿåòñÿ â òîì ñëó÷àå, åñëè
ïàðàìåòð <emphasis>loop</emphasis> íå ñîäåðæèò çíà÷åíèé.
</para>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Èìÿ àòðèáóòà</entry>
<entry>Òèï</entry>
<entry>Îáÿçàòåëåí</entry>
<entry>Ïî óìîë÷àíèþ</entry>
<entry>Îïèñàíèå</entry>
</row>
</thead>
<tbody>
<row>
<entry>name</entry>
<entry>string</entry>
<entry>Äà</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Íàçâàíèå ñåêöèè</entry>
</row>
<row>
<entry>loop</entry>
<entry>mixed</entry>
<entry>Äà</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Çíà÷åíèå, îïðåäåëÿþùåå êîëè÷åñòâî èòåðàöèé öèêëà.</entry>
</row>
<row>
<entry>start</entry>
<entry>integer</entry>
<entry>Íåò</entry>
<entry><emphasis>0</emphasis></entry>
<entry>
Èíäåêñ ïîçèöèè, ñ êîòîðîé áóäåò íà÷èíàòüñÿ
öèêë. Åñëè çíà÷åíèå îòðèöàòåëüíîå, òî íà÷àëüíàÿ ïîçèöèÿ
âû÷èñëÿåòñÿ îò êîíöà ìàññèâà. Íàïðèìåð, åñëè â ïåðåìåííîé
öèêëà 7 ýëåìåíòîâ è çíà÷åíèå àòðèáóòà start ðàâíî -2, òî
íà÷àëüíûé èíäåêñ áóäåò 5. Íåâåðíûå çíà÷åíèÿ (çíà÷åíèÿ, âíå
ìàññèâà) àâòîìàòè÷åñêè îáðåçàþòñÿ äî áëèæàéøåãî âåðíîãî
çíà÷åíèÿ.
</entry>
</row>
<row>
<entry>step</entry>
<entry>integer</entry>
<entry>Íåò</entry>
<entry><emphasis>1</emphasis></entry>
<entry>
Çíà÷åíèå øàãà, êîòîðîå èñïîëüçóåòñÿ äëÿ ïðîõîäà ïî
ìàññèâó. Íàïðèìåð, step=2 óêàçûâàåò îáõîä ìàññèâà
ïî ýëåìåíòàì 0,2,4... Åñëè øàã îòðèöàòåëåí, òî îáõîä
ìàññèâà áóäåò ïðîèçâîäèòñÿ â îáðàòíîì íàïðàâëåíèè.
</entry>
</row>
<row>
<entry>max</entry>
<entry>integer</entry>
<entry>Íåò</entry>
<entry><emphasis>1</emphasis></entry>
<entry>Ìàêñèìàëüíîå êîëè÷åñòâî èòåðàöèé öèêëà.</entry>
</row>
<row>
<entry>show</entry>
<entry>boolean</entry>
<entry>Íåò</entry>
<entry><emphasis>true</emphasis></entry>
<entry>Óêàçûâàåò, ïîêàçûâàòü èëè íåò ýòó ñåêöèþ</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<example>
<title>{section}</title>
<programlisting role="php">
<![CDATA[
<?php
$data = array(1000,1001,1002);
$smarty->assign('custid',$data);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{* ýòîò ïðèìåð íàïå÷àòàåò âñå çíà÷åíèÿ ìàññèâà $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}<br />
{/section}
<hr />
{* ýòîò ïðèìåð íàïå÷àòàåò âñå çíà÷åíèÿ ìàññèâà $custid â îáðàòíîì ïîðÿäêå *}
{section name=foo loop=$custid step=-1}
{$custid[foo]}<br />
{/section}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
id: 1000<br />
id: 1001<br />
id: 1002<br />
<hr />
id: 1002<br />
id: 1001<br />
id: 1000<br />
]]>
</screen>
<para>
Åù¸ íåìíîãî ïðèìåðîâ áåç ïðèñâîåííîãî ìàññèâà.
</para>
<programlisting>
<![CDATA[
{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}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
10 12 14 16 18
<hr />
20 18 16 14 12 10
]]>
</screen>
</example>
<example>
<title>Ïåðåìåííàÿ loop êîìàíäû {section}</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{*
ïåðåìåííàÿ loop îïðåäåëÿåò òîëüêî êîëè÷åñòâî èòåðàöèé.
âû ìîæåòå ïîëó÷àòü äîñòóï ê ëþáîé ïåðåìåííîé èç øàáëîíà âíóòðè ñåêöèè.
Ýòîò ïðèìåð ïðåäïîëàãàåò, ÷òî $custid, $name è $address âñå ÿâëÿþòñÿ
ìàññèâàìè, ñîäåðæàùèìè îäèíàêîâîå êîëè÷åñòâî çíà÷åíèé
*}
{section name=customer loop=$custid}
<p>
id: {$custid[customer]}<br />
name: {$name[customer]}<br />
address: {$address[customer]}
</p>
{/section}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
<p>
id: 1000<br />
name: John Smith<br />
address: 253 N 45th
</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>
]]>
</screen>
</example>
<example>
<title>èìåíîâàíèå {section}</title>
<programlisting>
<![CDATA[
{*
èìÿ ñåêöèè ìîæåò áûòü ëþáûì, òàê êàê îíî èñïîëüçóåòñÿ äëÿ îáðàùåíèÿ ê
äàííûì â ïðåäåëàõ ñåêöèè
*}
{section name=anything loop=$custid}
<p>
id: {$custid[anything]}<br />
name: {$name[anything]}<br />
address: {$address[anything]}
</p>
{/section}
]]>
</programlisting>
</example>
<example>
<title>âëîæåííûå ñåêöèè</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{*
ñåêöèè ìîãóò èìåòü âëîæåííîñòü ëþáîé ãëóáèíû. Èñïîëüçóÿ âëîæåííûå ñåêöèè,
âû ìîæåòå îáðàùàòüñÿ ê ñëîæíûì ñòðóêòóðàì äàííûõ, òàêèì êàê ìíîãîìåðíûå
ìàññèâû. Â ýòîì ïðèìåðå $contact_type[customer] - ýòî ìàññèâ
òèïîâ êîíòàêòîâ äëÿ òåêóùåãî êëèåíòà.
*}
{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}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
<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 />
]]>
</screen>
</example>
<example>
<title>ñåêöèè è àññîöèàòèâíûå ìàññèâû</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{*
Ýòî ïðèìåð âûâîäà àññîöèàòèâíîãî ìàññèâà
äàííûõ âíóòðè ñåêöèè
*}
{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}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
<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>
]]>
</screen>
<para>Áàçû äàííûõ (íàïðèìåð, PEAR èëè ADODB)</para>
<programlisting role="php">
<![CDATA[
<?php
$sql = 'select id, name, home, cell, email from contacts';
$smarty->assign('contacts',$db->getAll($sql) );
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{*
âûâîäèì ðåçóëüòàò çàïðîñà ê ÁÄ â òàáëèöó
*}
<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>
{/section}
</table>
]]>
</programlisting>
</example>
<example>
<title>{sectionelse}</title>
<programlisting>
<![CDATA[
{* sectionelse áóäåò âûïîëíåíà â òîì ñëó÷àå, åñëè $custid íå ñîäåðæèò çíà÷åíèé *}
{section name=customer loop=$custid}
id: {$custid[customer]}<br />
{sectionelse}
there are no values in $custid.
{/section}
]]>
</programlisting>
</example>
<para>
Ñåêöèè òàê æå èìåþò ñîáñòâåííûå ïåðåìåííûå, êîòîðûå ñîäåðæàò ñâîéñòâà ñåêöèé.
Îíè îáîçíà÷àþòñÿ òàê:
<link linkend="language.variables.smarty.loops">{$smarty.section.sectionname.varname}</link>
</para>
<note>
<para>
Íà÷èíàÿ ñ âåðñèè Smarty 1.5.0, ñèíòàêñèñ ïåðåìåííûõ ñâîéñòâ ñåññèé áûë
èçìåíåí ñ {%sectionname.varname%} íà {$smarty.section.sectionname.varname}.
Ñòàðûé ñèíòàêñèñ âñ¸ åù¸ ïîääåðæèâàåòñÿ, íî âû óâèäèòå ëèøü ïðèìåðû
íîâîãî ñèíòàêñèñà.
</para>
</note>
<sect2 id="section.property.index">
<title>index</title>
<para>
index èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ òåêóùåãî èíäåêñà ìàññèâà,
íà÷èíàÿ ñ íóëÿ (èëè ñ àòðèáóòà start, åñëè îí áûë óêàçàí) è óâåëè÷èâàÿñü
íà åäèíèöó (èëè íà çíà÷åíèå àòðèáóòà step, åñëè îí áûë óêàçàí).
</para>
<note>
<title>Òåõíè÷åñêîå Çàìå÷àíèå</title>
<para>
Åñëè àòðèáóòû step è start íå óêàçàíû, òî index
àíàëîãè÷åí àòðèáóòó ñåêöèè iteration, êðîìå òîãî,
÷òî íà÷èíàåòñÿ ñ 0, à íå ñ 1.
</para>
</note>
<example>
<title>ñâîéñòâà {section} index</title>
<programlisting>
<![CDATA[
{* ê âàøåìó ñâåäåíèþ, $custid[customer.index] è $custid[customer] îçíà÷àþò îäíî è òî æå *}
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
0 id: 1000<br />
1 id: 1001<br />
2 id: 1002<br />
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.index.prev">
<title>index_prev</title>
<para>
index_prev èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ ïðåäûäóùåãî èíäåêñà öèêëà
Íà ïåðâîé èòåðàöèè îí óñòàíîâëåí â -1.
</para>
</sect2>
<sect2 id="section.property.index.next">
<title>index_next</title>
<para>
index_next èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ ñëåäóþùåãî èíäåêñà öèêëà
Íà ïîñëåäíåé èòåðàöèè îí âñ¸ æå íà åäèíèöó áîëüøå òåêóùåãî (èëè íà äðóãîå
çíà÷åíèå, åñëè óêàçàí àòðèáóò step).
</para>
<example>
<title>ñâîéñòâà {section} index_next è index_prev</title>
<programlisting role="php">
<![CDATA[
<?php
$data = array(1001,1002,1003,1004,1005);
$smarty->assign('custid',$data);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{* ê âàøåìó ñâåäåíèþ, $custid[cus.index] è $custid[cus] îçíà÷àþò îäíî è òî æå *}
<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=cus loop=$custid}
<tr>
<td>{$smarty.section.cus.index}</td><td>{$custid[cus]}</td>
<td>{$smarty.section.cus.index_prev}</td><td>{$custid[cus.index_prev]}</td>
<td>{$smarty.section.cus.index_next}</td><td>{$custid[cus.index_next]}</td>
</tr>
{/section}
</table>
]]>
</programlisting>
<para>
Ðåçóëüòàòîì âûïîëíåíèÿ ýòîãî ïðèìåðà áóäåò òàáëèöà, ñîäåðæàùàÿ ñëåäóþùåå:
</para>
<screen>
<![CDATA[
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
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.iteration">
<title>iteration</title>
<para>
iteration èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ òåêóùåãî íîìåðà èòåðàöèè öèêëà.
</para>
<note>
<para>
Ýòî çíà÷åíèå íå çàâèñèò îò ñâîéñòâ start, step è max, â îòëè÷èå îò
ñâîéñòâà <link linkend="section.property.index">index</link>.
Êðîìå òîãî, èòåðàöèè íà÷èíàþòñÿ ñ åäèíèöû, à íå ñ íóëÿ, êàê èíäåêñû.
<link linkend="section.property.rownum">rownum</link> - ýòî ñèíîíèì ê
ñâîéñòâó iteration, îíè ðàáîòàþò îäèíàêîâî.
</para>
</note>
<example>
<title>ñâîéñòâî {section} iteration</title>
<programlisting role="php">
<![CDATA[
<?php
// array of 3000 to 3015
$id = range(3000,3015);
$smarty->assign('custid',$id);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{section name=cu loop=$custid start=5 step=2}
iteration={$smarty.section.cu.iteration}
index={$smarty.section.cu.index}
id={$custid[cu]}<br />
{/section}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
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 />
]]>
</screen>
<para>
Ýòîò ïðèìåð èñïîëüçóåò ñâîéñòâî iteration äëÿ
âûâîäà çàãîëîâêà òàáëèöû ÷åðåç êàæäûå ïÿòü ñòðî÷åê
(èñïîëüçóåò <link linkend="language.function.if">{if}</link>
ñ îïåðàòîðîì mod - îñòàòîê îò äåëåíèÿ).
</para>
<programlisting>
<![CDATA[
<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>
]]>
</programlisting>
</example>
</sect2>
<sect2 id="section.property.first">
<title>first</title>
<para>
Ïàðàìåòð first óñòàíîâëåí â true, åñëè òåêóùàÿ <link
linkend="section.property.iteration">èòåðàöèÿ</link> ñåêöèè
ÿâëÿåòñÿ ïåðâîé.
</para>
</sect2>
<sect2 id="section.property.last">
<title>last</title>
<para>
Ïàðàìåòð last óñòàíîâëåí â true, åñëè òåêóùàÿ <link
linkend="section.property.iteration">èòåðàöèÿ</link> ñåêöèè
ÿâëÿåòñÿ ïîñëåäíåé.
</para>
<example>
<title>ñâîéñòâà {section} first è last</title>
<para>
Ýòîò ïðèìåð ïðîõîäèò öèêëîì ïî ìàññèâó $customers,
âûâîäèò çàãîëîâîê íà ïåðâîé èòåðàöèè è ôóòåð íà ïîñëåäíåé
(èñïîëüçóåò ñâîéñòâî {section} <link linkend="section.property.total">total</link>)
</para>
<programlisting>
<![CDATA[
{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}
]]>
</programlisting>
</example>
</sect2>
<sect2 id="section.property.rownum">
<title>rownum</title>
<para>
rownum èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ òåêóùåãî íîìåðà èòåðàöèè öèêëà,
íà÷èíàÿ ñ åäèíèöû. Ýòî ñèíîíèì ñâîéñòâà <link
linkend="section.property.iteration">iteration</link>, îíè ðàáîòà èäåíòè÷íî.
</para>
</sect2>
<sect2 id="section.property.loop">
<title>loop</title>
<para>
loop èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ ïîñëåäíåãî íîìåðà èíäåêñà, ïî êîòîðîìó
ïðîõîäèëà èòåðàöèÿ ñåêöèè. Ýòî ñâîéñòâî ìîæåò áûòü èñïîëüçîâàíî êàê âíóòðè,
òàê è âíå ñåêöèè.
</para>
<example>
<title>ñâîéñòâî {section} index</title>
<programlisting>
<![CDATA[
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
There were {$smarty.section.customer.loop} customers shown above.
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
0 id: 1000<br />
1 id: 1001<br />
2 id: 1002<br />
There were 3 customers shown above.
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.show">
<title>show</title>
<para>
<emphasis>show</emphasis> èñïîëüçóåòñÿ â êà÷åñòâå ïàðàìåòðà ñåêöèè.
<emphasis>show</emphasis> ÿâëÿåòñÿ áóëåâûì çíà÷åíèåì, true èëè false.
Åñëè false, ñåêöèÿ íå áóäåò îòîáðàæåíà. Åñëè ïðèñóòñòâóåò ñåêöèÿ {sectionelse},
âìåñòî ýòîãî áóäåò îòîáðàæåíà îíà.
</para>
<example>
<title>àòðèáóò {section} show</title>
<programlisting>
<![CDATA[
{*
$show_customer_info (true/false) ìîæåò áûòü ïåðåäàí èç ïðèëîæåíèÿ PHP,
÷òîáû îïðåäåëèòü, íåîáõîäèìî ëè îòîáðàæàòü ñåêöèþ
*}
{section name=customer loop=$custid show=$show_customer_info}
{$smarty.section.customer.rownum} id: {$custid[customer]}<br />
{/section}
{if $smarty.section.customer.show}
the section was shown.
{else}
the section was not shown.
{/if}
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
1 id: 1000<br />
2 id: 1001<br />
3 id: 1002<br />
the section was shown.
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.total">
<title>total</title>
<para>
total èñïîëüçóåòñÿ äëÿ îòîáðàæåíèÿ êîëè÷åñòâà èòåðàöèé, ÷åðåç êîòîðûå
ïðîéäåò ýòà ñåêöèÿ. Ýòî ñâîéñòâî ìîæåò áûòü èñïîëüçîâàíî êàê âíóòðè, òàê
è âíå ñåêöèè.
</para>
<example>
<title>ñâîéñòâî {section} total</title>
<programlisting>
<![CDATA[
{section name=customer loop=$custid step=2}
{$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
There were {$smarty.section.customer.total} customers shown above.
]]>
</programlisting>
<para>
Ðåçóëüòàò âûïîëíåíèÿ äàííîãî ïðèìåðà:
</para>
<screen>
<![CDATA[
0 id: 1000<br />
2 id: 1002<br />
4 id: 1004<br />
There were 3 customers shown above.
]]>
</screen>
</example>
<para>
Ñì. òàêæå
<link linkend="language.function.foreach">{foreach}</link>
è
<link linkend="language.variables.smarty.loops">$smarty.section</link>.
</para>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->