Files
smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml

807 lines
20 KiB
XML
Raw Normal View History

2004-04-13 15:43:47 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2005-12-10 22:09:38 +00:00
<!-- EN-Revision: 1.14 Maintainer: yannick Status: ready -->
2004-05-23 15:44:59 +00:00
<sect1 id="language.function.section">
2005-12-10 22:09:38 +00:00
<title>{section},{sectionelse}</title>
<para>
Les balises <emphasis>section</emphasis> sont utilis<69>es pour
parcourir un <emphasis role="bold">tableau de donn<6E>es</emphasis>
(tout comme <link linkend="language.function.foreach">{foreach}</link>).
Toutes les balises <emphasis>{section}</emphasis> doivent <20>tre utilis<69>es
de paire avec les balises <emphasis>{/section}</emphasis>. Les param<61>tres
requis sont <emphasis>name</emphasis> et <emphasis>loop</emphasis>.
Le nom de la {section} est, selon votre choix, compos<6F> de lettres,
chiffres et underscores. Les sections peuvent <20>tre imbriqu<71>es,
mais leurs noms doivent <20>tre uniques. La variable de parcours
(g<>n<EFBFBD>ralement un tableau de donn<6E>es) d<>termine le nombre de fois
que la section sera parcourue. Lorsque l'on affiche une variable
dans une section, le nom de la section doit pr<70>c<EFBFBD>der
la variable entre crochets []. <emphasis>{sectionelse}</emphasis>
est ex<65>cut<75> lorsqu'aucune valeur n'est trouv<75>e dans la variable <20>
parcourir.
</para>
2004-05-23 15:44:59 +00:00
<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>Nom attribut</entry>
<entry>Type</entry>
<entry>Requis</entry>
<entry>Defaut</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>name</entry>
<entry>cha<EFBFBD>ne de caract<63>re</entry>
<entry>Oui</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Le nom de la section</entry>
</row>
<row>
<entry>loop</entry>
2004-12-21 21:08:13 +00:00
<entry>mixed</entry>
2004-05-23 15:44:59 +00:00
<entry>Oui</entry>
<entry><emphasis>n/a</emphasis></entry>
2004-12-21 21:08:13 +00:00
<entry>valeur qui d<>termine le nombre de fois que la boucle sera ex<65>cut<75>e.</entry>
2004-05-23 15:44:59 +00:00
</row>
<row>
<entry>start</entry>
<entry>entier</entry>
<entry>Non</entry>
<entry><emphasis>0</emphasis></entry>
<entry>La position de l'index ou la section commencera son
parcours. Si la valeur donn<6E>e est n<>gative, la position de
d<>part est calcul<75>e depuis la fin du tableau. Par exemple,
s'il existe 7 valeurs dans le tableau <20> parcourir et que start
est <20> -2, l'index de d<>part sera 5. Les valeurs incorrectes
(en dehors de la port<72>e du tableau) sont automatiquements
tronqu<71>es <20> la valeur correcte la plus proche.</entry>
</row>
<row>
<entry>step</entry>
<entry>entier</entry>
<entry>Non</entry>
<entry><emphasis>1</emphasis></entry>
<entry>La valeur du pas qui sera utilis<69> pour parcourir le
tableau.Par exemple, step=2 parcourera les indices
0,2,4, etc. Si step est n<>gatif, le tableau sera parcouru en sens
inverse.</entry>
</row>
<row>
<entry>max</entry>
<entry>entier</entry>
<entry>Non</entry>
<entry><emphasis>1</emphasis></entry>
<entry>D<EFBFBD>finit le nombre maximum de fois que le tableau sera
parcouru.</entry>
</row>
<row>
<entry>show</entry>
<entry>bool<EFBFBD>en</entry>
<entry>Non</entry>
<entry><emphasis>true</emphasis></entry>
<entry>D<EFBFBD>termine s'il est n<>cessaire d'afficher la
section ou non.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<example>
2005-12-10 22:09:38 +00:00
<title>{section}</title>
<programlisting role="php">
<![CDATA[
<?php
$data = array(1000,1001,1002);
$smarty->assign('custid',$data);
?>
]]>
</programlisting>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{* Cet exemple affiche toutes les valeurs du tableau $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}<br />
{/section}
<hr />
{* Affiche toutes les valeurs du tableau $custid dans le sens inverse *}
{section name=foo loop=$custid step=-1}
{$custid[foo]}<br />
2004-04-13 15:43:47 +00:00
{/section}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
id: 1000<br />
id: 1001<br />
id: 1002<br />
2005-12-10 22:09:38 +00:00
<hr />
id: 1002<br />
id: 1001<br />
id: 1000<br />
]]>
</screen>
<para>
Voici d'autres exemples sans tableaux assign<67>s.
</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>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
10 12 14 16 18
<hr />
20 18 16 14 12 10
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
2005-05-10 21:36:53 +00:00
2004-05-23 15:44:59 +00:00
<example>
2005-12-10 22:09:38 +00:00
<title>{section}, variable de parcours</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>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{*
La variable de parcours d<>termine uniquement le nombre de fois que nous allons
2004-04-13 15:43:47 +00:00
rentrer dans la boucle. Vous pouvez acc<63>der <20> toutes les variables du template
lorsque vous <20>tes dans une section. Cet exemple part du principe que
$idClient, $noms et $adresses sont tous des tableaux qui contiennent
2005-12-10 22:09:38 +00:00
autant de valeurs les uns que les autres.
*}
{section name=client loop=$idClient}
2005-12-10 22:09:38 +00:00
id : {$custid[customer]}<br />
nom : {$name[customer]}<br />
addresse : {$address[customer]}<br />
2005-05-10 21:36:53 +00:00
<p>
2004-04-13 15:43:47 +00:00
{/section}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
<p>
2005-12-10 22:09:38 +00:00
id : 1000<br />
nom : John Smith<br />
addresse : 253 N 45th
</p>
2005-05-10 21:36:53 +00:00
<p>
2005-12-10 22:09:38 +00:00
id : 1001<br />
nom : Jack Jones<br />
addresse : 417 Mulberry ln
</p>
2005-05-10 21:36:53 +00:00
<p>
2005-12-10 22:09:38 +00:00
id : 1002<br />
nom : Jane Munson<br />
addresse : 5605 apple st
</p>
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
2005-05-10 21:36:53 +00:00
2004-05-23 15:44:59 +00:00
<example>
2005-12-10 22:09:38 +00:00
<title>nom de {section}</title>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{*
Le nom de la section peut <20>tre ce que vous voulez,
et est utilis<69> pour r<>f<EFBFBD>rencer les donn<6E>es depuis la section.
*}
2004-04-13 15:43:47 +00:00
{section name=monTableau loop=$idClient}
2005-12-10 22:09:38 +00:00
<p>
2005-05-10 21:36:53 +00:00
id: {$idCLient[monTableau]}<br />
name: {$noms[monTableau]}<br />
2005-12-10 22:09:38 +00:00
address: {$addresses[monTableau]}
</p>
2005-05-10 21:36:53 +00:00
{/section}
]]>
</programlisting>
2004-05-23 15:44:59 +00:00
</example>
2005-05-10 21:36:53 +00:00
2004-05-23 15:44:59 +00:00
<example>
<title>sections imbriqu<71>es</title>
2005-12-10 22:09:38 +00:00
<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>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{*
Les sections peuvent <20>tre imbriqu<71>es <20> un nombre de niveaux illimit<69>.
2004-04-13 15:43:47 +00:00
Gr<47>ce aux sections imbriqu<71>es, vous pouvez acc<63>der <20> des structures de donn<6E>es
complexes, comme des tableaux multi-dimentionnels. Dans cet exemple,
$type_contact[client] est un tableau de type de contact pour le client
2005-12-10 22:09:38 +00:00
courant.
*}
{section name=client loop=$idClient}
2005-12-10 22:09:38 +00:00
<hr />
2005-05-10 21:36:53 +00:00
id: {$idClient[client]}<br />
nom: {$nom[client]}<br />
addresse: {$addresse[client]}<br />
2004-12-21 21:08:13 +00:00
{section name=contact loop=$type_contact[client]}
2005-05-10 21:36:53 +00:00
{$type_contact[client][contact]}: {$info_contact[client][contact]}<br />
2004-12-21 21:08:13 +00:00
{/section}
2004-04-13 15:43:47 +00:00
{/section}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
<hr />
2005-05-10 21:36:53 +00:00
id: 1000<br />
nom: John Smith<br />
addresse: 253 N 45th<br />
telephone: 555-555-5555<br />
telephone portable: 555-555-5555<br />
e-mail: john@myexample.com<br />
2005-12-10 22:09:38 +00:00
<hr />
2005-05-10 21:36:53 +00:00
id: 1001<br />
nom: Jack Jones<br />
addresse: 417 Mulberry ln<br />
telephone: 555-555-5555<br />
telephone portable: 555-555-5555<br />
e-mail: jack@myexample.com<br />
2005-12-10 22:09:38 +00:00
<hr />
2005-05-10 21:36:53 +00:00
id: 1002<br />
nom: Jane Munson<br />
addresse: 5605 apple st<br />
telephone: 555-555-5555<br />
telephone portable: 555-555-5555<br />
e-mail: jane@myexample.com<br />
2005-12-10 22:09:38 +00:00
<hr />
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
2005-05-10 21:36:53 +00:00
2004-05-23 15:44:59 +00:00
<example>
<title>Sections et tableaux associatifs</title>
2005-12-10 22:09:38 +00:00
<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>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{*
Exemple d'affichage d'un tableau associatif dans une section
*}
2004-04-13 15:43:47 +00:00
{section name=client loop=$contacts}
2005-12-10 22:09:38 +00:00
<p>
2005-05-10 21:36:53 +00:00
nom: {$contacts[client].name}<br />
telephone: {$contacts[client].home}<br />
portable: {$contacts[client].cell}<br />
2005-12-10 22:09:38 +00:00
e-mail: {$contacts[client].email}
</p>
2004-04-13 15:43:47 +00:00
{/section}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
<p>
2005-05-10 21:36:53 +00:00
nom: John Smith<br />
telephone: 555-555-5555<br />
portable: 555-555-5555<br />
2005-12-10 22:09:38 +00:00
e-mail: john@myexample.com
</p>
<p>
2005-05-10 21:36:53 +00:00
nom: Jack Jones<br />
telephone: 555-555-5555<br />
portable: 555-555-5555<br />
2005-12-10 22:09:38 +00:00
e-mail: jack@myexample.com
</p>
<p>
2005-05-10 21:36:53 +00:00
nom: Jane Munson<br />
telephone: 555-555-5555<br />
portable: 555-555-5555<br />
e-mail: jane@myexample.com<p>
2005-12-10 22:09:38 +00:00
</p>
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
2005-05-10 21:36:53 +00:00
2005-12-10 22:09:38 +00:00
<para>Exemple avec une base de donn<6E>es (eg. en utilisant Pear ou 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[
{*
Affiche le r<>sultat de la base de donn<6E>es dans un tableau
*}
<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>
2004-05-23 15:44:59 +00:00
<example>
2005-12-10 22:09:38 +00:00
<title>{sectionelse}</title>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2004-04-13 15:43:47 +00:00
{* sectionelse est ex<65>cut<75> s'il n'existe aucune valeur dans idClient *}
{section name=client loop=$idClient}
2005-05-10 21:36:53 +00:00
id: {$idClient[client]}<br />
2004-04-13 15:43:47 +00:00
{sectionelse}
2004-12-21 21:08:13 +00:00
Aucune valeur dans $idClient.
2005-05-10 21:36:53 +00:00
{/section}
]]>
</programlisting>
2004-05-23 15:44:59 +00:00
</example>
<para>
Les sections ont leur propre variable de gestion des propri<72>t<EFBFBD>s.
2005-05-24 20:46:11 +00:00
Elles sont de la forme:
<link linkend="language.variables.smarty.loops">{$smarty.section.sectionname.varname}</link>
2004-05-23 15:44:59 +00:00
</para>
<para>
2005-12-10 22:09:38 +00:00
Depuis Smarty 1.5.0, la syntaxe pour les propri<72>t<EFBFBD>s des sections
2004-05-23 15:44:59 +00:00
a <20>t<EFBFBD> chang<6E>e de {%sectionname.varname%} <20>
{$smarty.section.nomSection.nomVariable}. L'ancienne syntaxe est toujours
support<72>e, mais vous ne verrez que des exemples avec la nouvelle syntaxe
dans le manuel.
</para>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.index">
<title>index</title>
<para>
Index est utilis<69> pour afficher l'index de parcours courant, commence par
2005-12-10 22:09:38 +00:00
0 (ou l'attribut start s'il est fourni), et s'incr<63>mente de 1 (ou de la valeur
de l'attribut step s'il est fourni).
2004-05-23 15:44:59 +00:00
</para>
<note>
<title>Note technique</title>
<para>
Si les attributs step et start ne sont pas modifi<66>s, alors index
2005-12-10 22:09:38 +00:00
fonctionne de la m<>me fa<66>on que <link
2005-05-24 20:46:11 +00:00
linkend="section.property.iteration">iteration</link>, <20> l'exception qu'il commence
2004-05-23 15:44:59 +00:00
par 0 plut<75>t que par 1.
</para>
</note>
<example>
2005-12-10 22:09:38 +00:00
<title>propri<EFBFBD>t<EFBFBD> de {section} index</title>
<programlisting>
2005-05-10 21:36:53 +00:00
<![CDATA[
2005-12-10 22:09:38 +00:00
{* FYI, $custid[customer.index] et $custid[customer] sont identiques *}
2005-05-10 21:36:53 +00:00
{section name=client loop=$idClient}
2005-12-10 22:09:38 +00:00
{$smarty.section.client.index} id: {$idClient[client]}<br />
2005-05-10 21:36:53 +00:00
{/section}
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
0 id: 1000<br />
1 id: 1001<br />
2 id: 1002<br />
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.index.prev">
<title>index_prev</title>
<para>
index_prev est utilis<69> pour afficher l'index de parcours
pr<70>c<EFBFBD>dent de la boucle. Au premier passage, il vaut -1.
</para>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.index.next">
<title>index_next</title>
<para>
index_next est utilis<69> pour afficher la valeur th<74>orique suivante de
2004-12-26 21:12:45 +00:00
index. Dans la derni<6E>re boucle, cel<65> reste la valeur incr<63>ment<6E>e,
2004-05-23 15:44:59 +00:00
qui respecte l'attribut step si donn<6E>.
</para>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<example>
2005-12-10 22:09:38 +00:00
<title>propri<EFBFBD>t<EFBFBD> de {section} index_next et index_prev</title>
<programlisting role="php">
2005-05-10 21:36:53 +00:00
<![CDATA[
2005-12-10 22:09:38 +00:00
<?php
$data = array(1001,1002,1003,1004,1005);
$smarty->assign('custid',$data);
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
{* FYI, $custid[cus.index] et $custid[cus] sont identiques *}
<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>
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
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
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.iteration">
<title>iteration</title>
<para>
iteration est utilis<69> pour afficher la valeur courante de l'iteration.
</para>
<para>
NOTE: Cette valeur n'est pas affect<63>e par les attributs start, step et
2005-05-24 20:46:11 +00:00
max, <20> l'inverse de la propri<72>t<EFBFBD> <link linkend="section.property.index">index</link>.
L'it<69>ration commence par
1 et non par 0 (comme le fait index). <link
linkend="section.property.rownum">rownum</link> est un alias de iteration,
2004-05-23 15:44:59 +00:00
ils fonctionnent de la m<>me fa<66>on.
</para>
<example>
2005-12-10 22:09:38 +00:00
<title>propri<EFBFBD>t<EFBFBD> iteration de {section}</title>
<programlisting role="php">
<![CDATA[
<?php
// Tableau de 3000 <20> 3015
$id = range(3000,3015);
$smarty->assign('custid',$id);
?>
]]>
</programlisting>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{section name=cu loop=$custid start=5 step=2}
iteration={$smarty.section.cu.iteration}
index={$smarty.section.cu.index}
id={$custid[cu]}<br />
{/section}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
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 />
2005-05-10 21:36:53 +00:00
]]>
</screen>
2005-12-10 22:09:38 +00:00
<para>
Cet exemple utilise la propri<72>t<EFBFBD> iteration pour afficher
un block d'en-t<>te de tableau toutes les cinq lignes
(utilisez <link linkend="language.function.if">{if}</link>
avec l'op<6F>rateur 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>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.first">
<title>first</title>
<para>
first est <20> true lorsque la section est parcouru pour la premi<6D>re fois.
</para>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.last">
<title>last</title>
<para>
last est <20> true lorsque la section est parcourue pour la derni<6E>re fois.
</para>
<example>
2005-12-10 22:09:38 +00:00
<title>Propri<EFBFBD>t<EFBFBD> last et first de {section}</title>
<para>
Cet exemple boucle le tableau $customers ;
affiche un block d'en-t<>te lors de la premi<6D>re it<69>ration et,
<20> la derni<6E>re, affiche un block de pied de page
(utilisation de la propri<72>t<EFBFBD> <link linkend="section.property.total">total</link>)
</para>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{section name=customer loop=$customers}
{if $smarty.section.customer.first}
<table>
<tr><th>id</th><th>customer</th></tr>
{/if}
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
<tr>
<td>{$customers[customer].id}}</td>
<td>{$customers[customer].name}</td>
</tr>
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
{if $smarty.section.customer.last}
<tr><td></td><td>{$smarty.section.customer.total} customers</td></tr>
</table>
{/if}
{/section}
2005-05-10 21:36:53 +00:00
]]>
2005-12-10 22:09:38 +00:00
</programlisting>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.rownum">
<title>rownum</title>
<para>
rownum, utilis<69> pour afficher la valeur courante de l'it<69>ration,
2005-05-24 20:46:11 +00:00
commence par 1. C'est un alias de <link
linkend="section.property.iteration">iteration</link>, ils fonctionnent de fa<66>on
2004-05-23 15:44:59 +00:00
identique.
</para>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.loop">
<title>loop</title>
<para>
loop est utilis<69> pour afficher la derni<6E>re valeur de index que cette
section a utilis<69>. Peut <20>tre utilis<69> dans ou en dehors de la section.
</para>
<example>
2005-12-10 22:09:38 +00:00
<title>Propri<EFBFBD>t<EFBFBD> de {section} index</title>
<programlisting>
2005-05-10 21:36:53 +00:00
<![CDATA[
2005-12-10 22:09:38 +00:00
{section name=client loop=$idClient}
2005-05-10 21:36:53 +00:00
{$smarty.section.client.index} id: {$idClient[client]}<br />
2005-12-10 22:09:38 +00:00
{/section}
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
Il y eu {$smarty.section.client.loop} clients d'affich<63>s.
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
0 id: 1000<br />
1 id: 1001<br />
2 id: 1002<br />
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
Il y eu 3 clients d'affich<63>s.
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.show">
<title>show</title>
<para>
<emphasis>show</emphasis> est utilis<69> comme param<61>tre de section.
<emphasis>show</emphasis> est une valeur bool<6F>enne, true ou false.
Si show est <20> "false", la section ne sera pas affich<63>e. Si un
2005-12-10 22:09:38 +00:00
{sectionelse} est pr<70>sent, elle sera affich<63>e.
2004-05-23 15:44:59 +00:00
</para>
<example>
2005-12-10 22:09:38 +00:00
<title>{section}, attribut show</title>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{*
$show_client_info a pu <20>tre pass<73> par le script PHP,
pour d<>terminer si oui ou non on souhaite afficher la section
*}
{section name=client loop=$idClient show=$show_client_info}
2005-05-10 21:36:53 +00:00
{$smarty.section.client.rownum} id: {$idClient[client]}<br />
2005-12-10 22:09:38 +00:00
{/section}
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
{if $smarty.section.client.show}
la section a <20>t<EFBFBD> affich<63>e.
{else}
la section n'a pas <20>t<EFBFBD> affich<63>e.
{/if}
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
1 id: 1000<br />
2 id: 1001<br />
3 id: 1002<br />
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
la section a <20>t<EFBFBD> affich<63>e.
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
</sect2>
2005-12-10 22:09:38 +00:00
2004-05-23 15:44:59 +00:00
<sect2 id="section.property.total">
<title>total</title>
<para>
2005-12-10 22:09:38 +00:00
<literal>total</literal> est utilis<69> pour afficher le nombre d'it<69>ration que la section
2004-05-23 15:44:59 +00:00
va ex<65>cuter. Peut <20>tre utilis<69> dans ou en dehors de la section.
</para>
<example>
2005-12-10 22:09:38 +00:00
<title>{section}, propri<72>t<EFBFBD> <literal>total</literal></title>
2005-05-10 21:36:53 +00:00
<programlisting>
<![CDATA[
2005-12-10 22:09:38 +00:00
{section name=client loop=$idClient step=2}
{$smarty.section.client.index} id: {$idClient[client]}<br />
{/section}
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
Il y eu {$smarty.section.client.total} clients affich<63>s.
2005-05-10 21:36:53 +00:00
]]>
</programlisting>
<para>
L'exemple ci-dessus affichera :
</para>
<screen>
<![CDATA[
2005-12-10 22:09:38 +00:00
0 id: 1000<br />
2 id: 1001<br />
4 id: 1002<br />
2004-04-13 15:43:47 +00:00
2005-12-10 22:09:38 +00:00
Il y eu 3 clients affich<63>s.
2005-05-10 21:36:53 +00:00
]]>
</screen>
2004-05-23 15:44:59 +00:00
</example>
2005-05-24 20:46:11 +00:00
<para>
2005-12-10 22:09:38 +00:00
Voir aussi
2005-05-24 20:46:11 +00:00
<link linkend="language.function.foreach">{foreach}</link> et
<link linkend="language.variables.smarty.loops">$smarty.section</link>.
</para>
2004-05-23 15:44:59 +00:00
</sect2>
2004-04-13 15:43:47 +00:00
</sect1>
2005-12-10 22:09:38 +00:00
2004-04-13 15:43:47 +00:00
<!-- 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
2005-12-10 22:09:38 +00:00
-->