mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 13:51:36 +01:00
176 lines
4.1 KiB
XML
176 lines
4.1 KiB
XML
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|||
|
|
<!-- $Revision$ -->
|
|||
|
|
<sect1 id="language.assigned.variables">
|
|||
|
|
<title>Variables definidas desde PHP</title>
|
|||
|
|
<para>
|
|||
|
|
Las variables que son definidas desde PHP son referenciadas precedendo
|
|||
|
|
estas con una se<73>al de cifrado <literal>$</literal>. Las variables
|
|||
|
|
definidas dentro del template como una funci<63>n
|
|||
|
|
<link linkend="language.function.assign">assign</link> tambi<62>n son
|
|||
|
|
mostradas de esta manera.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
|
|||
|
|
<title>variables definidas</title>
|
|||
|
|
<programlisting>
|
|||
|
|
<![CDATA[
|
|||
|
|
Hello {$firstname}, glad to see you could make it.
|
|||
|
|
<br />
|
|||
|
|
Your last login was on {$lastLoginDate}.
|
|||
|
|
]]>
|
|||
|
|
</programlisting>
|
|||
|
|
<para>
|
|||
|
|
This will output:
|
|||
|
|
</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>Arreglos asociativos</title>
|
|||
|
|
<para>
|
|||
|
|
Usted tambi<62>n puede referenciar matrices asociativas en variables
|
|||
|
|
que son definidas desde PHP especificando la clave despu<70>s del
|
|||
|
|
simbolo '.'(punto).
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Accesando variables de matriz asociativa</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>
|
|||
|
|
where the content of index.tpl is:
|
|||
|
|
</para>
|
|||
|
|
<programlisting>
|
|||
|
|
<![CDATA[
|
|||
|
|
{$Contacts.fax}<br />
|
|||
|
|
{$Contacts.email}<br />
|
|||
|
|
{* you can print arrays of arrays as well *}
|
|||
|
|
{$Contacts.phone.home}<br />
|
|||
|
|
{$Contacts.phone.cell}<br />
|
|||
|
|
]]>
|
|||
|
|
</programlisting>
|
|||
|
|
<para>
|
|||
|
|
this will output:
|
|||
|
|
</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><EFBFBD>ndices de Matrices</title>
|
|||
|
|
<para>
|
|||
|
|
Usted podra referencia matrizes por su <20>ndice, muy semejantes a la
|
|||
|
|
sintaxis de PHP.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Accesando matrices por sus <20>ndices</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>
|
|||
|
|
where index.tpl is:
|
|||
|
|
</para>
|
|||
|
|
<programlisting>
|
|||
|
|
<![CDATA[
|
|||
|
|
{$Contacts[0]}<br />
|
|||
|
|
{$Contacts[1]}<br />
|
|||
|
|
{* you can print arrays of arrays as well *}
|
|||
|
|
{$Contacts[2][0]}<br />
|
|||
|
|
{$Contacts[2][1]}<br />
|
|||
|
|
]]>
|
|||
|
|
</programlisting>
|
|||
|
|
<para>
|
|||
|
|
This will output:
|
|||
|
|
</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>Objetos</title>
|
|||
|
|
<para>
|
|||
|
|
Las propiedades de los objetos definidos desde PHP pueden ser
|
|||
|
|
referenciados especificando el nombre de la propiedad despu<70>;s
|
|||
|
|
del simbolo '->'.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Accesando propiedades de objetos</title>
|
|||
|
|
<programlisting>
|
|||
|
|
<![CDATA[
|
|||
|
|
name: {$person->name}<br />
|
|||
|
|
email: {$person->email}<br />
|
|||
|
|
]]>
|
|||
|
|
</programlisting>
|
|||
|
|
<para>
|
|||
|
|
this will output:
|
|||
|
|
</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
|
|||
|
|
-->
|