Files
smarty/docs/fr/designers/language-custom-functions/language-function-html-options.xml

214 lines
5.9 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-04 17:56:06 +00:00
<!-- EN-Revision: 1.12 Maintainer: yannick Status: ready -->
2004-05-23 15:50:53 +00:00
<sect1 id="language.function.html.options">
2005-12-04 17:56:06 +00:00
<title>{html_options}</title>
<para>
{html_options} est une
<link linkend="language.custom.functions">fonction personnalis<69>e</link>
qui cr<63>e un groupe d'options avec les donn<6E>es fournies. Elle prend en charge
les <20>l<EFBFBD>ments s<>lectionn<6E>s par d<>faut. Les attributs requis sont values et output,
<20> moins que vous n'utilisiez options <20> la place.
</para>
2004-05-23 15:50:53 +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>values</entry>
<entry>array</entry>
<entry>Oui, <20> 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, <20> moins que vous n'utilisiez
l'attribut options</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Un tableau de libell<6C>s pour la liste
d<>roulante</entry>
</row>
<row>
<entry>selected</entry>
<entry>cha<EFBFBD>ne de caract<63>res/tableau</entry>
<entry>Non</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Les <20>l<EFBFBD>ments s<>lectionn<6E>s</entry>
</row>
<row>
<entry>options</entry>
<entry>Tableau associatif</entry>
<entry>Oui, <20> moins que vous n'utilisiez option
et values</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Un tableau associatif valeur / libell<6C></entry>
</row>
<row>
<entry>name</entry>
<entry>cha<EFBFBD>ne de caract<63>res</entry>
<entry>Non</entry>
<entry><emphasis>empty</emphasis></entry>
<entry>Nom du goupe d'options</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Si la valeur donn<6E>e est un tableau, elle sera trait<69>e comme un
2005-12-04 17:56:06 +00:00
&lt;optgroup&gt; html, et affich<63>e. La r<>cursivit<69> est support<72>e avec
&lt;optgroup&gt;. La sortie est compatible XHTML.
2004-05-23 15:50:53 +00:00
</para>
<para>
Si l'attribut optionnel <emphasis>name</emphasis> est donn<6E>, les
balises &lt;select name="groupname"&gt;&lt;/select&gt; entoureront la
2005-12-04 17:56:06 +00:00
liste d'options. Sinon, seule la liste &lt;option&gt; sera g<>n<EFBFBD>r<EFBFBD>e.
2004-05-23 15:50:53 +00:00
</para>
<para>
Tous les param<61>tres qui ne sont pas dans la liste ci-dessus sont
2005-12-04 17:56:06 +00:00
affich<63>s en tant que paires nom / valeur dans la balise &lt;select&gt;. Ils
sont ignor<6F>s si le param<61>tre optionnel <emphasis>name</emphasis>
n'est pas donn<6E>.
2004-05-23 15:50:53 +00:00
</para>
<example>
2005-12-04 17:56:06 +00:00
<title>{html_options}</title>
<para>
<emphasis role="bold">Exemple 1 :</emphasis>
</para>
<programlisting role="php">
2004-12-22 19:59:35 +00:00
<![CDATA[
2005-12-04 17:56:06 +00:00
<?php
2004-04-13 15:43:47 +00:00
2005-12-04 17:56:06 +00:00
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
$smarty->assign('cust_names', array(
'Joe Schmoe',
'Jack Smith',
'Jane Johnson',
'Charlie Brown'));
$smarty->assign('customer_id', 1001);
2004-04-13 15:43:47 +00:00
2005-12-04 17:56:06 +00:00
?>
2005-05-11 09:47:36 +00:00
]]>
</programlisting>
<para>
2005-12-04 17:56:06 +00:00
O<> le template est :
2005-05-11 09:47:36 +00:00
</para>
<programlisting>
<![CDATA[
2005-12-04 17:56:06 +00:00
<select name="customer_id">
{html_options values=$cust_ids output=$cust_names selected=$customer_id}
2004-12-22 19:59:35 +00:00
</select>
2005-05-11 09:47:36 +00:00
]]>
</programlisting>
<para>
2005-12-04 17:56:06 +00:00
<emphasis role="bold">Exemple 2 :</emphasis>
2005-05-11 09:47:36 +00:00
</para>
<programlisting>
<![CDATA[
2005-12-04 17:56:06 +00:00
<?php
2004-04-13 15:43:47 +00:00
2004-12-22 19:59:35 +00:00
$smarty->assign('cust_options', array(
2005-12-04 17:56:06 +00:00
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown')
);
$smarty->assign('customer_id', 1001);
2004-04-13 15:43:47 +00:00
2005-12-04 17:56:06 +00:00
?>
2005-05-11 09:47:36 +00:00
]]>
</programlisting>
<para>
2005-12-04 17:56:06 +00:00
O<> le template est :
2005-05-11 09:47:36 +00:00
</para>
<programlisting>
<![CDATA[
2005-12-04 17:56:06 +00:00
{html_options name=customer_id options=$cust_options selected=$customer_id}
2005-05-11 09:47:36 +00:00
]]>
</programlisting>
<para>
Les deux exemples afficheront :
</para>
<screen>
<![CDATA[
2005-12-04 17:56:06 +00:00
<select name="customer_id">
<option label="Joe Schmoe" value="1000">Joe Schmoe</option>
<option label="Jack Smith" value="1001" selected="selected">Jack Smith</option>
<option label="Jane Johnson" value="1002">Jane Johnson</option>
<option label="Charlie Brown" value="1003">Charlie Brown</option>
2004-12-22 19:59:35 +00:00
</select>
]]>
2005-05-11 09:47:36 +00:00
</screen>
2004-05-23 15:50:53 +00:00
</example>
2005-12-04 17:56:06 +00:00
<example>
<title>{html_options} - Exemple avec une base de donn<6E>es (eg PEAR ou ADODB):</title>
<programlisting role="php">
<![CDATA[
<?php
$sql = 'select type_id, types from types order by type';
$smarty->assign('types',$db->getAssoc($sql));
$sql = 'select contact_id, name, email, type_id
from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));
?>
]]>
</programlisting>
<para>
o<> le template est :
</para>
<programlisting>
<![CDATA[
<select name="type_id">
<option value='null'>-- none --</option>
{html_options name="type" options=$types selected=$contact.type_id}
</select>
]]>
</programlisting>
</example>
<para>
Voir aussi
<link linkend="language.function.html.checkboxes">{html_checkboxes}</link> et
<link linkend="language.function.html.radios">{html_radios}</link>.
</para>
2004-04-13 15:43:47 +00:00
</sect1>
2005-12-04 17:56:06 +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-04 17:56:06 +00:00
-->