mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 13:51:36 +01:00
281 lines
8.0 KiB
XML
281 lines
8.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.17 Maintainer: yannick Status: ready -->
|
|
|
|
<sect1 id="language.function.html.options">
|
|
<title>{html_options}</title>
|
|
<para>
|
|
<varname>{html_options}</varname> est une
|
|
<link linkend="language.custom.functions">fonction personnalisée</link>
|
|
qui crée un groupe d'options avec les données fournies. Elle prend en charge
|
|
les éléments sélectionnés par défaut.
|
|
</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>Nom attribut</entry>
|
|
<entry>Type</entry>
|
|
<entry>Requis</entry>
|
|
<entry>Defaut</entry>
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>values</entry>
|
|
<entry>array</entry>
|
|
<entry>Oui, à moins que vous n'utilisiez
|
|
l'attribut options</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Un tableau de valeurs pour les listes
|
|
déroulantes</entry>
|
|
</row>
|
|
<row>
|
|
<entry>output</entry>
|
|
<entry>array</entry>
|
|
<entry>Oui, à moins que vous n'utilisiez
|
|
l'attribut options</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Un tableau de libellés pour la liste
|
|
déroulante</entry>
|
|
</row>
|
|
<row>
|
|
<entry>selected</entry>
|
|
<entry>chaîne de caractères/tableau</entry>
|
|
<entry>Non</entry>
|
|
<entry><emphasis>empty</emphasis></entry>
|
|
<entry>Les éléments sélectionnés</entry>
|
|
</row>
|
|
<row>
|
|
<entry>options</entry>
|
|
<entry>Tableau associatif</entry>
|
|
<entry>Oui, à moins que vous n'utilisiez option
|
|
et values</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Un tableau associatif valeur / libellé</entry>
|
|
</row>
|
|
<row>
|
|
<entry>name</entry>
|
|
<entry>chaîne de caractères</entry>
|
|
<entry>Non</entry>
|
|
<entry><emphasis>empty</emphasis></entry>
|
|
<entry>Nom du goupe d'options</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
Les attributs requis sont
|
|
<parameter>values</parameter> et <parameter>output</parameter>,
|
|
à moins que vous n'utilisiez <parameter>options</parameter> à la place.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Si l'attribut optionnel <parameter>name</parameter> est fourni, les balises
|
|
<literal><select></select></literal> seront créées,
|
|
sinon, UNIQUEMENT la liste <literal><option></literal> sera générée.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Si la valeur fournie est un tableau, il sera traité comme un
|
|
<literal><optgroup></literal> HTML, et affichera les groupes.
|
|
La récursivité est supportée avec <literal><optgroup></literal>.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Tous les paramètres qui ne sont pas dans la liste ci-dessus sont affichés
|
|
sous la forme de paire nom/valeur dans la balise
|
|
<literal><select></literal>. Ils seront ignorés si le paramètre optionnel
|
|
<parameter>name</parameter> n'est pas fourni.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Tous les affichages sont conformes XHTML.
|
|
</para></listitem>
|
|
</itemizedlist>
|
|
|
|
<example>
|
|
<title>Un tableau associatif avec l'attribut <varname>options</varname></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty->assign('myOptions', array(
|
|
1800 => 'Joe Schmoe',
|
|
9904 => 'Jack Smith',
|
|
2003 => 'Charlie Brown')
|
|
);
|
|
$smarty->assign('mySelect', 9904);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Le template suivant génèrera une liste. Notez la présence
|
|
de l'attribut <parameter>name</parameter> qui crée les
|
|
balises <literal><select></literal>.
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{html_options name=foo options=$myOptions selected=$mySelect}
|
|
]]>
|
|
</programlisting>
|
|
|
|
<para>
|
|
L'affichage de l'exemple ci-dessus sera :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
<select name="foo">
|
|
<option label="Joe Schmoe" value="1800">Joe Schmoe</option>
|
|
<option label="Jack Smith" value="9904" selected="selected">Jack Smith</option>
|
|
<option label="Charlie Brown" value="2003">Charlie Brown</option>
|
|
</select>
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Tableaux séparés pour <varname>values</varname> et
|
|
<varname>ouptut</varname></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty->assign('cust_ids', array(56,92,13));
|
|
$smarty->assign('cust_names', array(
|
|
'Joe Schmoe',
|
|
'Jane Johnson',
|
|
'Charlie Brown'));
|
|
$smarty->assign('customer_id', 92);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Les tableaux ci-dessus seront affichés avec le template suivant
|
|
(notez l'utilisation de la fonction PHP <ulink url="&url.php-manual;function.count">
|
|
<varname>count()</varname></ulink> en tant que modificateur pour
|
|
définir la taille du select).
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<select name="customer_id" size="{$cust_names|@count}">
|
|
{html_options values=$cust_ids output=$cust_names selected=$customer_id}
|
|
</select>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
L'exemple ci-dessous affichera :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
<select name="customer_id">
|
|
<option label="Joe Schmoe" value="56">Joe Schmoe</option>
|
|
<option label="Jack Smith" value="92" selected="selected">Jane Johnson</option>
|
|
<option label="Charlie Brown" value="13">Charlie Brown</option>
|
|
</select>
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Exemple avec une base de données (e.g. ADODB ou PEAR)</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$sql = 'select type_id, types from contact_types order by type';
|
|
$smarty->assign('contact_types',$db->getAssoc($sql));
|
|
|
|
$sql = 'select contact_id, name, email, contact_type_id
|
|
from contacts where contact_id='.$contact_id;
|
|
$smarty->assign('contact',$db->getRow($sql));
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Où le template pourrait être celui-ci. Notez l'utilisation du modificateur
|
|
<link linkend="language.modifier.truncate"><varname>truncate</varname></link>.
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<select name="type_id">
|
|
<option value='null'>-- none --</option>
|
|
{html_options options=$contact_types|truncate:20 selected=$contact.type_id}
|
|
</select>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Exemple avec <optgroup> </title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
|
|
$arr['Rest'] = array(3 => 'Sauna',1 => 'Massage');
|
|
$smarty->assign('lookups', $arr);
|
|
$smarty->assign('fav', 7);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>Le script ci-dessus et le template suivant
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{html_options name=foo options=$myOptions selected=$mySelect}
|
|
]]>
|
|
</programlisting>
|
|
|
|
<para>
|
|
affichera :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
<select name="breakTime">
|
|
<optgroup label="Sport">
|
|
<option label="Golf" value="6">Golf</option>
|
|
<option label="Cricket" value="9">Cricket</option>
|
|
<option label="Swim" value="7" selected="selected">Swim</option>
|
|
</optgroup>
|
|
<optgroup label="Rest">
|
|
<option label="Sauna" value="3">Sauna</option>
|
|
<option label="Massage" value="1">Massage</option>
|
|
</optgroup>
|
|
</select>
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<para>
|
|
Voir aussi
|
|
<link linkend="language.function.html.checkboxes"><varname>{html_checkboxes}</varname></link>
|
|
et
|
|
<link linkend="language.function.html.radios"><varname>{html_radios}</varname></link>
|
|
</para>
|
|
</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
|
|
--> |