mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-02 13:21:36 +01:00
174 lines
4.0 KiB
XML
174 lines
4.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.assigned.variables">
|
|
<title>Variabili valorizzate da PHP</title>
|
|
<para>
|
|
Le variabili valorizzate da PHP sono referenziate facendole precedere
|
|
da un segno di dollaro <literal>$</literal>. Anche le variabili
|
|
valorizzate internamente al template con la funzione <link
|
|
linkend="language.function.assign">assign</link> vengono visualizzate
|
|
in questo modo.
|
|
</para>
|
|
<example>
|
|
|
|
<title>variabili valorizzate</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
Hello {$firstname}, glad to see you could make it.
|
|
<br />
|
|
Your last login was on {$lastLoginDate}.
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Questo visualizzerà:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Hello Doug, glad to see you could make it.
|
|
<br />
|
|
Your last login was on January 11th, 2001.
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
|
|
<sect2 id="language.variables.assoc.arrays">
|
|
<title>Array associativi</title>
|
|
<para>
|
|
Potete fare riferimento ad array associativi valorizzati da
|
|
PHP specificando l'indice dopo il punto '.'
|
|
</para>
|
|
<example>
|
|
<title>accesso ad array associativi</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>
|
|
dove il contenuto di index.tpl è:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{$Contacts.fax}<br />
|
|
{$Contacts.email}<br />
|
|
{* ovviamente si possono usare anche array multidimensionali *}
|
|
{$Contacts.phone.home}<br />
|
|
{$Contacts.phone.cell}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
questo visualizzerà:
|
|
</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>Array con indici numerici</title>
|
|
<para>
|
|
Potete referenziare gli array con il loro indice, come in PHP.
|
|
</para>
|
|
<example>
|
|
<title>accesso agli array per indice numerico</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>
|
|
dove index.tpl è:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{$Contacts[0]}<br />
|
|
{$Contacts[1]}<br />
|
|
{* anche qui si possono usare array multidimensionali *}
|
|
{$Contacts[2][0]}<br />
|
|
{$Contacts[2][1]}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Questo visualizzerà:
|
|
</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>Oggetti</title>
|
|
<para>
|
|
Le proprietà di oggetti valorizzate da PHP possono essere
|
|
referenziate indicando il nome della proprietà dopo il
|
|
simbolo '->'
|
|
</para>
|
|
<example>
|
|
<title>accesso alle proprietà degli oggetti</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
name: {$person->name}<br />
|
|
email: {$person->email}<br />
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Questo visualizzerà:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
name: 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
|
|
-->
|