mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 21:01:37 +01:00
176 lines
4.1 KiB
XML
176 lines
4.1 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.3 Maintainer: gerald Status: ready -->
|
|
<sect1 id="language.assigned.variables">
|
|
<title>Variables assignées depuis PHP</title>
|
|
<para>
|
|
Pour utiliser une variables assignées depuis PHP, il
|
|
faut la préfixer par le symbole dollar <literal>$</literal>.
|
|
Les variables asignées depuis un template grâce à la fonction
|
|
<link linkend="language.function.assign">{assign}</link> sont
|
|
manipulées de la même façon.
|
|
</para>
|
|
<example>
|
|
<title>Variables assignées</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
Bienvenue {$prenom}, heureux de voir que tu es arrivé ici.
|
|
<p>
|
|
La dernière connexion remonte au {$dateConnexionPrecedente}.
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Celà va afficher:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Bienvenue Doug, heureux de voir que tu es arrivé ici.
|
|
<p>
|
|
La dernière connexion remonte au 11 janvier 2001.
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
|
|
<sect2 id="language.variables.assoc.arrays">
|
|
<title>Tableaux associatifs</title>
|
|
<para>
|
|
Vous pouvez également utiliser des variables sous forme de tableaux
|
|
associatifs assignées depuis PHP en en spécifiant la clef,
|
|
après le symbole '.' (point).
|
|
</para>
|
|
<example>
|
|
<title>Accéder aux variables de tableaux associatifs</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$smarty = new Smarty;
|
|
$smarty->assign('Contacts',
|
|
array('fax' => '555-222-9876',
|
|
'email' => 'zaphod@slartibartfast.com',
|
|
'phone' => array('home' => '555-444-3333',
|
|
'cell' => '555-111-1234')));
|
|
$smarty->display('index.tpl');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
où index.tpl est :
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{$Contacts.fax}<br />
|
|
{$Contacts.email}<br />
|
|
{* vous pouvez afficher des tableaux de tableaux *}
|
|
{$Contacts.phone.home}<br />
|
|
{$Contacts.phone.cell}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Ce qui donne en sortie :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
555-222-9876<br />
|
|
zaphod@slartibartfast.com<br />
|
|
555-444-3333<br />
|
|
555-111-1234<br />
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</sect2>
|
|
|
|
<sect2 id="language.variables.array.indexes">
|
|
<title>Tableaux indexés</title>
|
|
<para>
|
|
Vous pouvez utiliser des tableaux indexés de la même façon
|
|
que vous le faites en PHP.
|
|
</para>
|
|
<example>
|
|
<title>Accès aux tableaux grâce à l'index</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty = new Smarty;
|
|
$smarty->assign('Contacts',
|
|
array('555-222-9876',
|
|
'zaphod@slartibartfast.com',
|
|
array('555-444-3333',
|
|
'555-111-1234')));
|
|
$smarty->display('index.tpl');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Où index.tpl est :
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{$Contacts[0]}<br />
|
|
{$Contacts[1]}<br />
|
|
{* Vous pouvez également afficher des tableaux *}
|
|
{$Contacts[2][0]}<br />
|
|
{$Contacts[2][1]}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
ce qui donne en sortie :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
555-222-9876<br />
|
|
zaphod@slartibartfast.com<br />
|
|
555-444-3333<br />
|
|
555-111-1234<br />
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</sect2>
|
|
<sect2 id="language.variables.objects">
|
|
<title>Objets</title>
|
|
<para>
|
|
Les attributs des <link linkend="advanced.features.objects">objets</link>
|
|
assignés depuis PHP peuvent être utilisées en
|
|
en spécifiant le nom après le symbole '->'.
|
|
</para>
|
|
<example>
|
|
<title>accéder aux attributs des objets</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
nom: {$person->name}<br />
|
|
email: {$person->email}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Ce qui donne en sortie :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
nom: Zaphod Beeblebrox<br />
|
|
email: zaphod@slartibartfast.com<br />
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</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
|
|
--> |