cvs: smarty /docs/fr/designers/language-builtin-functions language-function-section.xml
[email protected] ("Yannick Torres") Mon, 09 Oct 2006 15:55:58 -0000
| Newsgroups | php.smarty.cvs |
|---|---|
| Message-ID | <cvsyannick1160409358@cvsserver> |
yannick Mon Oct 9 15:55:58 2006 UTC
Modified files:
/smarty/docs/fr/designers/language-builtin-functions
language-function-section.xml
Log:
sync with EN
yannick-20061009155558.txt
(text/plain, 37.8 KB)
http://cvs.php.net/viewvc.cgi/smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml?r1=1.9&r2=1.10&diff_format=u
Index: smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml
diff -u smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml:1.9 smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml:1.10
--- smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml:1.9 Sat Dec 10 22:09:36 2005
+++ smarty/docs/fr/designers/language-builtin-functions/language-function-section.xml Mon Oct 9 15:55:58 2006
@@ -1,26 +1,19 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.9 $ -->
-<!-- EN-Revision: 1.14 Maintainer: yannick Status: ready -->
+<!-- $Revision: 1.10 $ -->
+<!-- EN-Revision: 1.18 Maintainer: yannick Status: ready -->
<sect1 id="language.function.section">
<title>{section},{sectionelse}</title>
- <para>
- Les balises <emphasis>section</emphasis> sont utilisées pour
- parcourir un <emphasis role="bold">tableau de données</emphasis>
- (tout comme <link linkend="language.function.foreach">{foreach}</link>).
- Toutes les balises <emphasis>{section}</emphasis> doivent être utilisées
- de paire avec les balises <emphasis>{/section}</emphasis>. Les paramètres
- requis sont <emphasis>name</emphasis> et <emphasis>loop</emphasis>.
- Le nom de la {section} est, selon votre choix, composé de lettres,
- chiffres et underscores. Les sections peuvent être imbriquées,
- mais leurs noms doivent être uniques. La variable de parcours
- (généralement un tableau de donné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écéder
- la variable entre crochets []. <emphasis>{sectionelse}</emphasis>
- est exécuté lorsqu'aucune valeur n'est trouvée dans la variable à
- parcourir.
- </para>
+ <para>
+ Une <varname>{section}</varname>
+ sert à boucler dans des <emphasis role="bold">tableaux de données</emphasis>,
+ contrairement à <link linkend="language.function.foreach"><varname>{foreach}</varname></link>
+ qui est utilisé pour boucler dans un
+ <emphasis role="bold">simple tableau associatif</emphasis>.
+ Chaque balise <varname>{section}</varname> doit aller de paire avec une
+ balise <varname>{/section}</varname> fermante.
+ </para>
+
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
@@ -33,7 +26,7 @@
<entry>Nom attribut</entry>
<entry>Type</entry>
<entry>Requis</entry>
- <entry>Defaut</entry>
+ <entry>Défaut</entry>
<entry>Description</entry>
</row>
</thead>
@@ -50,20 +43,22 @@
<entry>mixed</entry>
<entry>Oui</entry>
<entry><emphasis>n/a</emphasis></entry>
- <entry>valeur qui détermine le nombre de fois que la boucle sera exécutée.</entry>
+ <entry>Valeur qui détermine le nombre de fois que la boucle sera exécutée</entry>
</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
+ <entry>
+ La position de l'index ou la section commencera son
parcours. Si la valeur donnée est négative, la position de
départ est calculée depuis la fin du tableau. Par exemple,
s'il existe 7 valeurs dans le tableau à parcourir et que start
est à -2, l'index de départ sera 5. Les valeurs incorrectes
(en dehors de la portée du tableau) sont automatiquements
- tronquées à la valeur correcte la plus proche.</entry>
+ tronquées à la valeur correcte la plus proche
+ </entry>
</row>
<row>
<entry>step</entry>
@@ -73,49 +68,104 @@
<entry>La valeur du pas qui sera utilisé 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>
+ inverse</entry>
</row>
<row>
<entry>max</entry>
<entry>entier</entry>
<entry>Non</entry>
- <entry><emphasis>1</emphasis></entry>
+ <entry><emphasis>n/a</emphasis></entry>
<entry>Définit le nombre maximum de fois que le tableau sera
- parcouru.</entry>
+ parcouru</entry>
</row>
<row>
<entry>show</entry>
<entry>booléen</entry>
- <entry>Non</entry>
- <entry><emphasis>true</emphasis></entry>
+ <entry>No</entry>
+ <entry><emphasis>&true;</emphasis></entry>
<entry>Détermine s'il est nécessaire d'afficher la
- section ou non.</entry>
+ section ou non</entry>
</row>
</tbody>
</tgroup>
</informaltable>
- <example>
- <title>{section}</title>
+ <itemizedlist>
+ <listitem><para>
+ Les paramètres requis sont <parameter>name</parameter> et <parameter>loop</parameter>.
+ </para></listitem>
+
+ <listitem><para>
+ Le <parameter>name</parameter> de la <varname>{section}</varname> est, selon votre choix,
+ composé de lettres, chiffres et underscores, comme pour les
+ <ulink url="&url.php-manual;language.variables">variables PHP</ulink>.
+ </para></listitem>
+
+ <listitem><para>
+ Les sections peuvent être imbriquées mais leurs noms doivent être uniques.
+ </para></listitem>
+
+ <listitem><para>
+ L'attribut <parameter>loop</parameter>, habituellement un tableau de valeurs,
+ détermine le nombre de fois que
+ <varname>{section}</varname> doit boucler.
+ </para></listitem>
+
+ <listitem><para>
+ Lors de l'affichage d'une variable dans une <varname>{section}</varname>, le nom de la
+ <varname>{section}</varname> doit être fournis après le nom de la variable entre crochets [].
+ </para></listitem>
+
+ <listitem><para>
+ <varname>{sectionelse}</varname> est exécuté lorsqu'aucune valeur n'est trouvée dans la variable à
+ parcourir.
+ </para></listitem>
+
+ <listitem><para>
+ <varname>{section}</varname> a également ces propres variables qui gérent les propriétés
+ de la <varname>{section}</varname>.
+ Ces propriétés sont accessibles comme ceci : <link linkend="language.variables.smarty.loops">
+ <parameter>{$smarty.section.name.property}</parameter></link>
+ où <quote>name</quote> est l'attribut <parameter>name</parameter>.
+ </para></listitem>
+
+ <listitem><para>
+ Les propriétés de <varname>{section}</varname> sont
+ <link linkend="section.property.index"><parameter>index</parameter></link>,
+ <link linkend="section.property.index.prev"><parameter>index_prev</parameter></link>,
+ <link linkend="section.property.index.next"><parameter>index_next</parameter></link>,
+ <link linkend="section.property.iteration"><parameter>iteration</parameter></link>,
+ <link linkend="section.property.first"><parameter>first</parameter></link>,
+ <link linkend="section.property.last"><parameter>last</parameter></link>,
+ <link linkend="section.property.rownum"><parameter>rownum</parameter></link>,
+ <link linkend="section.property.loop"><parameter>loop</parameter></link>,
+ <link linkend="section.property.show"><parameter>show</parameter></link>,
+ <link linkend="section.property.total"><parameter>total</parameter></link>.
+ </para></listitem>
+</itemizedlist>
- <programlisting role="php">
+ <example>
+ <title>Boucler dans un simple tableau avec {section}</title>
+<para>
+<link linkend="api.assign"><varname>assign()</varname></link> un tableau à Smarty
+</para>
+<programlisting role="php">
<![CDATA[
<?php
-
$data = array(1000,1001,1002);
$smarty->assign('custid',$data);
-
?>
]]>
- </programlisting>
+</programlisting>
+<para>Le template qui affiche le tableau</para>
<programlisting>
- <![CDATA[
-{* Cet exemple affiche toutes les valeurs du tableau $custid *}
+<![CDATA[
+{* Cet exemple affichera 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 *}
+{* Affiche toutes les valeurs du tableau $custid, en ordre inverse *}
{section name=foo loop=$custid step=-1}
{$custid[foo]}<br />
{/section}
@@ -135,25 +185,27 @@
id: 1000<br />
]]>
</screen>
- <para>
- Voici d'autres exemples sans tableaux assignés.
- </para>
- <programlisting>
+ </example>
+
+
+ <example>
+ <title>{section} sans un tableau assigné</title>
+<programlisting>
<![CDATA[
{section name=foo start=10 loop=20 step=2}
-{$smarty.section.foo.index}
+ {$smarty.section.foo.index}
{/section}
<hr />
{section name=bar loop=21 max=6 step=-2}
-{$smarty.section.bar.index}
+ {$smarty.section.bar.index}
{/section}
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
-<![CDATA[
+</programlisting>
+<para>
+ L'exemple ci-dessus affichera :
+</para>
+<screen>
+ <![CDATA[
10 12 14 16 18
<hr />
20 18 16 14 12 10
@@ -161,38 +213,59 @@
</screen>
</example>
- <example>
- <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);
+<example>
+ <title>Nommage d'une {section}</title>
+ <para>
+ Le <parameter>name</parameter> de la <varname>{section}</varname> peut être ce que vous
+ voulez, voir les <ulink url="&url.php-manual;language.variables">variables PHP</ulink>.
+ Il sera utilisé pour référencer les données de la <varname>{section}</varname>.
+ </para>
+ <programlisting>
+<![CDATA[
+{section name=anything loop=$myArray}
+ {$myArray[anything].foo}
+ {$name[anything]}
+ {$address[anything].bar}
+{/section}
+]]>
+ </programlisting>
+ </example>
-$addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');
-$smarty->assign('address',$addr);
+ <example>
+ <title>Boucler dans un tableau associatif avec {section}</title>
+ <para>
+ Voici un exemple d'affichage d'un tableau associatif de données avec
+ <varname>{section}</varname>. Ce qui suit est le script PHP assignant
+ le tableau <parameter>$contacts</parameter> à Smarty.
+ </para>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+$data = array(
+ array('name' => 'John Smith', 'home' => '555-555-5555',
+ 'cell' => '666-555-5555', 'email' => '[email protected]'),
+ array('name' => 'Jack Jones', 'home' => '777-555-5555',
+ 'cell' => '888-555-5555', 'email' => '[email protected]'),
+ array('name' => 'Jane Munson', 'home' => '000-555-5555',
+ 'cell' => '123456', 'email' => '[email protected]')
+ );
+$smarty->assign('contacts',$data);
?>
]]>
</programlisting>
+
+<para>Le template pour afficher <parameter>$contacts</parameter></para>
<programlisting>
<![CDATA[
-{*
- La variable de parcours détermine uniquement le nombre de fois que nous allons
- rentrer dans la boucle. Vous pouvez accéder à toutes les variables du template
- lorsque vous êtes dans une section. Cet exemple part du principe que
- $idClient, $noms et $adresses sont tous des tableaux qui contiennent
- autant de valeurs les uns que les autres.
-*}
-{section name=client loop=$idClient}
- id : {$custid[customer]}<br />
- nom : {$name[customer]}<br />
- addresse : {$address[customer]}<br />
- <p>
+{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>
@@ -202,46 +275,33 @@
<screen>
<![CDATA[
<p>
- id : 1000<br />
- nom : John Smith<br />
- addresse : 253 N 45th
+ name: John Smith<br />
+ home: 555-555-5555<br />
+ cell: 666-555-5555<br />
+ e-mail: [email protected]
</p>
<p>
- id : 1001<br />
- nom : Jack Jones<br />
- addresse : 417 Mulberry ln
+ name: Jack Jones<br />
+ home phone: 777-555-5555<br />
+ cell phone: 888-555-5555<br />
+ e-mail: [email protected]
</p>
<p>
- id : 1002<br />
- nom : Jane Munson<br />
- addresse : 5605 apple st
+ name: Jane Munson<br />
+ home phone: 000-555-5555<br />
+ cell phone: 123456<br />
+ e-mail: [email protected]
</p>
]]>
</screen>
- </example>
-
- <example>
- <title>nom de {section}</title>
- <programlisting>
-<![CDATA[
-{*
- Le nom de la section peut être ce que vous voulez,
- et est utilisé pour référencer les données depuis la section.
-*}
-{section name=monTableau loop=$idClient}
-<p>
- id: {$idCLient[monTableau]}<br />
- name: {$noms[monTableau]}<br />
- address: {$addresses[monTableau]}
- </p>
-{/section}
-]]>
- </programlisting>
- </example>
+</example>
<example>
- <title>sections imbriquées</title>
- <programlisting role="php">
+ <title>{section} démontrant l'utilisation de la variable <varname>loop</varname></title>
+ <para>Cet exemple suppose que <parameter>$custid</parameter>, <parameter>$name</parameter>
+ et <parameter>$address</parameter> sont tous des tableaux contenant le même
+ nombre de valeurs. Tout d'abord, le script PHP qui assigne les tableaux à Smarty.</para>
+<programlisting role="php">
<![CDATA[
<?php
@@ -251,43 +311,24 @@
$fullnames = array('John Smith','Jack Jones','Jane Munson');
$smarty->assign('name',$fullnames);
-$addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');
+$addr = array('253 Abbey road', '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', '[email protected]'),
- array( '123-456-4', 'www.example.com'),
- array( '0457878')
-);
-$smarty->assign('contact_info', $info);
-
?>
]]>
- </programlisting>
+</programlisting>
+<para>La variable <parameter>loop</parameter> détermine uniquement le nombre
+ de fois qu'il faut boucler.
+ Vous pouvez accéder à n'importe quelle variable du template dans la
+ <varname>{section}</varname></para>
<programlisting>
<![CDATA[
-{*
- Les sections peuvent être imbriquées à un nombre de niveaux illimité.
- Grâce aux sections imbriquées, vous pouvez accéder à des structures de données
- complexes, comme des tableaux multi-dimentionnels. Dans cet exemple,
- $type_contact[client] est un tableau de type de contact pour le client
- courant.
-*}
-{section name=client loop=$idClient}
-<hr />
- id: {$idClient[client]}<br />
- nom: {$nom[client]}<br />
- addresse: {$addresse[client]}<br />
- {section name=contact loop=$type_contact[client]}
- {$type_contact[client][contact]}: {$info_contact[client][contact]}<br />
- {/section}
+{section name=customer loop=$custid}
+<p>
+ id: {$custid[customer]}<br />
+ name: {$name[customer]}<br />
+ address: {$address[customer]}
+</p>
{/section}
]]>
</programlisting>
@@ -296,63 +337,77 @@
</para>
<screen>
<![CDATA[
-<hr />
-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: [email protected]<br />
-<hr />
-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: [email protected]<br />
-<hr />
-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: [email protected]<br />
-<hr />
+<p>
+ id: 1000<br />
+ name: John Smith<br />
+ address: 253 Abbey road
+</p>
+<p>
+ id: 1001<br />
+ name: Jack Jones<br />
+ address: 417 Mulberry ln
+</p>
+<p>
+ id: 1002<br />
+ name: Jane Munson<br />
+ address: 5605 apple st
+</p>
]]>
</screen>
</example>
+
+
<example>
- <title>Sections et tableaux associatifs</title>
+ <title>{section} imbriquée</title>
+ <para>
+ Les sections peuvent être imbriquées autant de fois que vous le voulez.
+ Avec les sections imbriquées, vous pouvez accéder aux structures de données
+ complexes, comme les tableaux multi-dimentionnels. Voici un script PHP qui assigne les
+ tableaux.
+ </para>
<programlisting role="php">
<![CDATA[
<?php
-$data = array(
- array('name' => 'John Smith', 'home' => '555-555-5555',
- 'cell' => '666-555-5555', 'email' => '[email protected]'),
- array('name' => 'Jack Jones', 'home' => '777-555-5555',
- 'cell' => '888-555-5555', 'email' => '[email protected]'),
- array('name' => 'Jane Munson', 'home' => '000-555-5555',
- 'cell' => '123456', 'email' => '[email protected]')
-);
-$smarty->assign('contacts',$data);
+$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', '[email protected]'),
+ array( '123-456-4', 'www.example.com'),
+ array( '0457878')
+ );
+$smarty->assign('contact_info', $info);
?>
-]]>
- </programlisting>
+ ]]>
+</programlisting>
+<para>Dans ce template, <emphasis>$contact_type[customer]</emphasis> est un tableau de
+ types de contacts.</para>
<programlisting>
<![CDATA[
-{*
- Exemple d'affichage d'un tableau associatif dans une section
-*}
-{section name=client loop=$contacts}
-<p>
- nom: {$contacts[client].name}<br />
- telephone: {$contacts[client].home}<br />
- portable: {$contacts[client].cell}<br />
- e-mail: {$contacts[client].email}
-</p>
+{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>
@@ -361,110 +416,92 @@
</para>
<screen>
<![CDATA[
-<p>
-nom: John Smith<br />
-telephone: 555-555-5555<br />
-portable: 555-555-5555<br />
-e-mail: [email protected]
-</p>
-<p>
-nom: Jack Jones<br />
-telephone: 555-555-5555<br />
-portable: 555-555-5555<br />
-e-mail: [email protected]
-</p>
-<p>
-nom: Jane Munson<br />
-telephone: 555-555-5555<br />
-portable: 555-555-5555<br />
-e-mail: [email protected]<p>
-</p>
+<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: [email protected]<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>
- <para>Exemple avec une base de donné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) );
+<example>
+<title>Exemple avec une base de données et {sectionelse}</title>
+ <para>Les résultats d'une recherche dans une base de données
+ (e.g. ADODB ou PEAR) sont assignés à Smarty</para>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+$sql = 'select id, name, home, cell, email from contacts '
+ ."where name like '$foo%' ";
+$smarty->assign('contacts', $db->getAll($sql));
?>
]]>
- </programlisting>
-
- <programlisting>
-<![CDATA[
-{*
-Affiche le résultat de la base de données dans un tableau
-*}
-<table>
- <tr><th> </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>
- <title>{sectionelse}</title>
+</programlisting>
+<para>Le template pour afficher le résultat de la base de données dans un tableau HTML</para>
<programlisting>
<![CDATA[
-{* sectionelse est exécuté s'il n'existe aucune valeur dans idClient *}
-{section name=client loop=$idClient}
- id: {$idClient[client]}<br />
+<table>
+<tr><th> </th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr>
+{section name=co loop=$contacts}
+ <tr>
+ <td><a href="view.php?id={$contacts[co].id}">view<a></td>
+ <td>{$contacts[co].name}</td>
+ <td>{$contacts[co].home}</td>
+ <td>{$contacts[co].cell}</td>
+ <td>{$contacts[co].email}</td>
+ <tr>
{sectionelse}
- Aucune valeur dans $idClient.
+ <tr><td colspan="5">Aucun élément n'a été trouvé</td></tr>
{/section}
+</table>
]]>
- </programlisting>
+</programlisting>
</example>
- <para>
- Les sections ont leur propre variable de gestion des propriétés.
- Elles sont de la forme:
- <link linkend="language.variables.smarty.loops">{$smarty.section.sectionname.varname}</link>
- </para>
- <para>
- Depuis Smarty 1.5.0, la syntaxe pour les propriétés des sections
- a été changée de {%sectionname.varname%} à
- {$smarty.section.nomSection.nomVariable}. L'ancienne syntaxe est toujours
- supportée, mais vous ne verrez que des exemples avec la nouvelle syntaxe
- dans le manuel.
- </para>
+
<sect2 id="section.property.index">
- <title>index</title>
+ <title>.index</title>
<para>
- Index est utilisé pour afficher l'index de parcours courant, commence par
- 0 (ou l'attribut start s'il est fourni), et s'incrémente de 1 (ou de la valeur
- de l'attribut step s'il est fourni).
+ <parameter>index</parameter> contient l'index courant du tableau, en commençant par zéro ou par
+ <parameter>start</parameter> s'il est fourni. Il s'incrémente d'un en un ou de
+ <parameter>step</parameter> s'il est fourni.
</para>
<note>
<title>Note technique</title>
<para>
- Si les attributs step et start ne sont pas modifiés, alors index
- fonctionne de la même façon que <link
- linkend="section.property.iteration">iteration</link>, à l'exception qu'il commence
- par 0 plutôt que par 1.
+ Si les propriétés <parameter>step</parameter> et <parameter>start</parameter>
+ ne sont pas modifiés, alors le fonctionnement est le même que celui de la propriété
+ <link linkend="section.property.iteration"><parameter>iteration</parameter></link>,
+ mise à part qu'il commence à zéro au lieu de un.
</para>
</note>
<example>
- <title>propriété de {section} index</title>
+<title>Exemple avec la propriété <varname>index</varname></title>
+<para>
+<note><title>FYI</title>
+<para><literal>$custid[customer.index]</literal> et
+<literal>$custid[customer]</literal> sont identiques.</para>
+</note>
+</para>
<programlisting>
<![CDATA[
-{* FYI, $custid[customer.index] et $custid[customer] sont identiques *}
-
-{section name=client loop=$idClient}
- {$smarty.section.client.index} id: {$idClient[client]}<br />
+{section name=customer loop=$custid}
+ {$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
]]>
</programlisting>
@@ -481,61 +518,61 @@
</example>
</sect2>
+
<sect2 id="section.property.index.prev">
- <title>index_prev</title>
+ <title>.index_prev</title>
<para>
- index_prev est utilisé pour afficher l'index de parcours
- précédent de la boucle. Au premier passage, il vaut -1.
+ <parameter>index_prev</parameter> est l'index de la boucle précédente.
+ Lors de la première boucle, il vaut -1.
</para>
</sect2>
<sect2 id="section.property.index.next">
- <title>index_next</title>
+ <title>.index_next</title>
<para>
- index_next est utilisé pour afficher la valeur théorique suivante de
- index. Dans la dernière boucle, celà reste la valeur incrémentée,
- qui respecte l'attribut step si donné.
+ <parameter>index_next</parameter> est l'index de la prochaine boucle.
+ Lors de la prochaine boucle, il vaudra un de moins que l'index courant, suivant
+ la configuration de l'attribut <parameter>step</parameter>, s'il est fourni.
</para>
<example>
- <title>propriété de {section} index_next et index_prev</title>
- <programlisting role="php">
+<title>Exemple avec les propriétés <varname>index</varname>, <varname>index_next</varname>
+ et <varname>index_prev</varname></title>
+<programlisting role="php">
<![CDATA[
<?php
-
$data = array(1001,1002,1003,1004,1005);
-$smarty->assign('custid',$data);
-
+$smarty->assign('rows',$data);
?>
]]>
- </programlisting>
+</programlisting>
+<para>Le template pour afficher le tableau ci-dessus dans un tableau HTML</para>
<programlisting>
- <![CDATA[
-{* FYI, $custid[cus.index] et $custid[cus] sont identiques *}
-
+<![CDATA[
+{* $rows[row.index] et $rows[row] 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}
+ <tr>
+ <th>index</th><th>id</th>
+ <th>index_prev</th><th>prev_id</th>
+ <th>index_next</th><th>next_id</th>
+ </tr>
+{section name=row loop=$rows}
+ <tr>
+ <td>{$smarty.section.row.index}</td><td>{$rows[row]}</td>
+ <td>{$smarty.section.row.index_prev}</td><td>{$rows[row.index_prev]}</td>
+ <td>{$smarty.section.row.index_next}</td><td>{$rows[row.index_next]}</td>
+ </tr>
+{/section}
</table>
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
+ </programlisting>
+ <para>
+ L'exemple ci-dessus affichera un tableau HTML contenant :
+ </para>
+ <screen>
<![CDATA[
index id index_prev prev_id index_next next_id
-0 1001 -1 1 1002
+0 1001 -1 1 1002
1 1002 0 1001 2 1003
2 1003 1 1002 3 1004
3 1004 2 1003 4 1005
@@ -545,45 +582,50 @@
</example>
</sect2>
+
<sect2 id="section.property.iteration">
- <title>iteration</title>
- <para>
- iteration est utilisé pour afficher la valeur courante de l'iteration.
- </para>
+ <title>.iteration</title>
<para>
- NOTE: Cette valeur n'est pas affectée par les attributs start, step et
- max, à l'inverse de la propriété <link linkend="section.property.index">index</link>.
- L'itération commence par
- 1 et non par 0 (comme le fait index). <link
- linkend="section.property.rownum">rownum</link> est un alias de iteration,
- ils fonctionnent de la même façon.
+ <parameter>iteration</parameter> contient l'itération courante de la boucle et commence à un.
</para>
+ <note>
+ <para>
+ Ceci n'est pas affecté par les propriétés <varname>{section}</varname>
+ <parameter>start</parameter>, <parameter>step</parameter> et
+ <parameter>max</parameter> contrairement à la propriété
+ <link linkend="section.property.index"><parameter>index</parameter></link>.
+ <parameter>iteration</parameter> commence également à un au lieu de zéro
+ contrairement à <parameter>index</parameter>.
+ <link linkend="section.property.rownum"><parameter>rownum</parameter></link>
+ est un alias de <parameter>iteration</parameter>, ils sont identiques.
+ </para>
+ </note>
<example>
- <title>propriété iteration de {section}</title>
- <programlisting role="php">
+<title>Exemple avec la propriété <varname>iteration</varname></title>
+<programlisting role="php">
<![CDATA[
<?php
-
-// Tableau de 3000 à 3015
+// array of 3000 to 3015
$id = range(3000,3015);
-$smarty->assign('custid',$id);
-
+$smarty->assign('arr',$id);
?>
]]>
- </programlisting>
+</programlisting>
+<para>Le template pour afficher tous les autres éléments du tableau <literal>$arr</literal> comme
+ <literal>step=2</literal></para>
<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 name=cu loop=$arr start=5 step=2}
+ iteration={$smarty.section.cu.iteration}
+ index={$smarty.section.cu.index}
+ id={$custid[cu]}<br />
{/section}
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
+ </programlisting>
+ <para>
+ L'exemple ci-dessus affichera :
+ </para>
+ <screen>
<![CDATA[
iteration=1 index=5 id=3005<br />
iteration=2 index=7 id=3007<br />
@@ -593,194 +635,183 @@
iteration=6 index=15 id=3015<br />
]]>
</screen>
- <para>
- Cet exemple utilise la propriété 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érateur mod).
- </para>
+ <para>
+ Un autre exemple d'utilisation de la propriété
+ <parameter>iteration</parameter> est d'afficher un bloc d'en-tête d'un tableau toutes
+ les 5 lignes.
+ Utilisez la fonction <link linkend="language.function.if"><varname>{if}</varname></link>
+ avec l'opérateur mod.
+ </para>
<programlisting>
<![CDATA[
<table>
- {section name=co loop=$contacts}
- {if $smarty.section.co.iteration % 5 == 1}
- <tr><th> </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}
+{section name=co loop=$contacts}
+ {if $smarty.section.co.iteration % 5 == 1}
+ <tr><th> </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>
+ </programlisting>
+</example>
</sect2>
+
<sect2 id="section.property.first">
- <title>first</title>
+ <title>.first</title>
<para>
- first est à true lorsque la section est parcouru pour la première fois.
+ <parameter>first</parameter> est défini à &true; si l'itération courante de
+ <varname>{section}</varname> est l'initiale.
</para>
</sect2>
+
<sect2 id="section.property.last">
- <title>last</title>
+ <title>.last</title>
<para>
- last est à true lorsque la section est parcourue pour la dernière fois.
+ <parameter>last</parameter> est défini à &true;
+ si l'itération courante de la section est la dernière.
</para>
<example>
- <title>Propriété last et first de {section}</title>
+ <title>Exemple avec les propriétés <varname>first</varname> et <varname>last</varname></title>
<para>
- Cet exemple boucle le tableau $customers ;
- affiche un block d'en-tête lors de la première itération et,
- à la dernière, affiche un block de pied de page
- (utilisation de la propriété <link linkend="section.property.total">total</link>)
+ Cet exemple boucle sur le tableau <varname>$customers</varname>,
+ affiche un bloc d'en-tête lors de la première itération et, lors de la dernière,
+ affiche un bloc de pied de page. Utilise aussi la propriété
+ <link linkend="section.property.total"><parameter>total</parameter></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}
+ {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>
+ <title>.rownum</title>
<para>
- rownum, utilisé pour afficher la valeur courante de l'itération,
- commence par 1. C'est un alias de <link
- linkend="section.property.iteration">iteration</link>, ils fonctionnent de façon
- identique.
+ <parameter>rownum</parameter> contient l'itération courante de la boucle,
+ commençant à un. C'est un alias de <link
+ linkend="section.property.iteration"><parameter>iteration</parameter></link>,
+ ils fonctionnent exactement de la même façon.
</para>
</sect2>
<sect2 id="section.property.loop">
- <title>loop</title>
+ <title>.loop</title>
<para>
- loop est utilisé pour afficher la dernière valeur de index que cette
- section a utilisé. Peut être utilisé dans ou en dehors de la section.
- </para>
+ <parameter>loop</parameter> contient le dernier index de la boucle de la section.
+ Il peut être utilisé dans ou après la <varname>{section}</varname>.
+ </para>
<example>
- <title>Propriété de {section} index</title>
+ <title>Exemple avec la propriété <varname>loop</varname></title>
<programlisting>
<![CDATA[
-{section name=client loop=$idClient}
- {$smarty.section.client.index} id: {$idClient[client]}<br />
+{section name=customer loop=$custid}
+ {$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
-
-Il y eu {$smarty.section.client.loop} clients d'affichés.
+There are {$smarty.section.customer.loop} customers shown above.
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
+ </programlisting>
+ <para>
+ L'exemple ci-dessus affichera :
+ </para>
+ <screen>
<![CDATA[
0 id: 1000<br />
1 id: 1001<br />
2 id: 1002<br />
-
-Il y eu 3 clients d'affichés.
+There are 3 customers shown above.
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.show">
- <title>show</title>
+ <title>.show</title>
<para>
- <emphasis>show</emphasis> est utilisé comme paramètre de section.
- <emphasis>show</emphasis> est une valeur booléenne, true ou false.
- Si show est à "false", la section ne sera pas affichée. Si un
- {sectionelse} est présent, elle sera affichée.
+ <parameter>show</parameter> est utilisé en tant que paramètre à la section et est une valeur booléenne.
+ S'il vaut &false;, la section ne sera pas affichée. S'il y a un
+ <varname>{sectionelse}</varname>, il sera affiché de façon alternative.
</para>
<example>
- <title>{section}, attribut show</title>
+ <title>Exemple avec la propriété <varname>show</varname></title>
+ <para>Une valeur booléenne <varname>$show_customer_info</varname> est passée
+ depuis l'application PHP, pour réguler l'affichage ou non de cette section.</para>
<programlisting>
<![CDATA[
-{*
- $show_client_info a pu être passé 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}
- {$smarty.section.client.rownum} id: {$idClient[client]}<br />
+{section name=customer loop=$customers show=$show_customer_info}
+ {$smarty.section.customer.rownum} id: {$customers[customer]}<br />
{/section}
-{if $smarty.section.client.show}
- la section a été affichée.
+{if $smarty.section.customer.show}
+ the section was shown.
{else}
- la section n'a pas été affichée.
+ the section was not shown.
{/if}
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
+ </programlisting>
+ <para>
+ L'exemple ci-dessus affichera :
+ </para>
+ <screen>
<![CDATA[
1 id: 1000<br />
2 id: 1001<br />
3 id: 1002<br />
-la section a été affichée.
+the section was shown.
]]>
</screen>
</example>
</sect2>
<sect2 id="section.property.total">
- <title>total</title>
+ <title>.total</title>
<para>
- <literal>total</literal> est utilisé pour afficher le nombre d'itération que la section
- va exécuter. Peut être utilisé dans ou en dehors de la section.
+ <parameter>total</parameter> contient le nombre d'itérations que cette
+ <varname>{section}</varname> bouclera. Il peut être utilisé dans ou après une
+ <varname>{section}</varname>.
</para>
<example>
- <title>{section}, propriété <literal>total</literal></title>
+ <title>Exemple avec la propriété <varname>total</varname></title>
<programlisting>
<![CDATA[
-{section name=client loop=$idClient step=2}
- {$smarty.section.client.index} id: {$idClient[client]}<br />
+{section name=customer loop=$custid step=2}
+ {$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
-
-Il y eu {$smarty.section.client.total} clients affichés.
+ There are {$smarty.section.customer.total} customers shown above.
]]>
- </programlisting>
- <para>
- L'exemple ci-dessus affichera :
- </para>
- <screen>
-<![CDATA[
-0 id: 1000<br />
-2 id: 1001<br />
-4 id: 1002<br />
-
-Il y eu 3 clients affichés.
-]]>
- </screen>
+ </programlisting>
</example>
<para>
Voir aussi
- <link linkend="language.function.foreach">{foreach}</link> et
- <link linkend="language.variables.smarty.loops">$smarty.section</link>.
+ <link linkend="language.function.foreach"><varname>{foreach}</varname></link> et
+ <link linkend="language.variables.smarty.loops"><parameter>$smarty.section</parameter></link>.
</para>
</sect2>
</sect1>