2004-10-07 18:50:52 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
|
|
<!-- $Revision$ -->
|
|
|
|
|
|
<sect1 id="language.function.section">
|
|
|
|
|
|
<title>section,sectionelse</title>
|
|
|
|
|
|
<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>Nombre del Atributo</entry>
|
|
|
|
|
|
<entry>Tipo</entry>
|
|
|
|
|
|
<entry>Requerido</entry>
|
|
|
|
|
|
<entry>Default</entry>
|
|
|
|
|
|
<entry>Descripci<EFBFBD>n</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>name</entry>
|
|
|
|
|
|
<entry>string</entry>
|
|
|
|
|
|
<entry>Si</entry>
|
|
|
|
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
|
|
|
|
<entry>El nombre de la section</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>loop</entry>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<entry>mixed</entry>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<entry>Si</entry>
|
|
|
|
|
|
<entry><emphasis>n/a</emphasis></entry>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<entry>El nombre de la variable para determinar el n<>mero de iteracciones</entry>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>start</entry>
|
|
|
|
|
|
<entry>integer</entry>
|
|
|
|
|
|
<entry>No</entry>
|
|
|
|
|
|
<entry><emphasis>0</emphasis></entry>
|
|
|
|
|
|
<entry> La posici<63>n del <20>ndice de la section donde va a comenzar.
|
|
|
|
|
|
Si el valor es negativo, la posici<63>n del inicio se calculara
|
|
|
|
|
|
a partir del final de la matriz. Por ejemplo, si hubieran 7 valores
|
|
|
|
|
|
en la matriz y comienza por -2, el <20>ndice inicial es 5.
|
|
|
|
|
|
Valores inv<6E>lidos (valores fuera del tama<6D>o de la matriz) son
|
|
|
|
|
|
autom<6F>ticamente truncados para el valor valido mas pr<70>ximo.
|
|
|
|
|
|
</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>step</entry>
|
|
|
|
|
|
<entry>integer</entry>
|
|
|
|
|
|
<entry>No</entry>
|
|
|
|
|
|
<entry><emphasis>1</emphasis></entry>
|
|
|
|
|
|
<entry>El valor del step que sera usado para el loop de la matriz.
|
|
|
|
|
|
Por ejemplo, step=2 realizara el loop con los <20>ndices 0,2,4, etc.
|
|
|
|
|
|
Si step es negativo, este avanzara en la matriz de atras para adelante.
|
|
|
|
|
|
</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>max</entry>
|
|
|
|
|
|
<entry>integer</entry>
|
|
|
|
|
|
<entry>No</entry>
|
|
|
|
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
|
|
|
|
<entry>Def<EFBFBD>ne el n<>mero m<>ximo de ciclos(loops) para la section.</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
<row>
|
|
|
|
|
|
<entry>show</entry>
|
|
|
|
|
|
<entry>boolean</entry>
|
|
|
|
|
|
<entry>No</entry>
|
|
|
|
|
|
<entry><emphasis>true</emphasis></entry>
|
|
|
|
|
|
<entry>Determina cuando mostrar o no esta secci<63>n</entry>
|
|
|
|
|
|
</row>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</tgroup>
|
|
|
|
|
|
</informaltable>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Las section del template son usada para realizar un ciclo(loop) de
|
2005-11-08 23:37:29 +00:00
|
|
|
|
un <emphasis role="bold">arreglo de datos</emphasis>.
|
|
|
|
|
|
(al agiual que un <link linkend="language.function.foreach">{foreach}</link>).
|
|
|
|
|
|
Todas las etiquetas <emphasis>section</emphasis>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
deben tener su par <emphasis>/section</emphasis>. Los par<61>metros
|
|
|
|
|
|
requeridos son <emphasis>name</emphasis> y <emphasis>loop</emphasis>.
|
|
|
|
|
|
El nombre de la section puede ser el que usted quiera, formado por
|
|
|
|
|
|
letras, n<>meros y subrayados. Las sections pueden ser anidadas, y los
|
|
|
|
|
|
nombres de la section anidadas deben ser diferentes unos de otros.
|
|
|
|
|
|
Las variables del loop (normalmente una matriz de valores) determina
|
|
|
|
|
|
el n<>mero de veces del loop de la section. Cuando estuviera mostrando
|
|
|
|
|
|
una variable dentro de una section, el nombre de la section debe estar
|
|
|
|
|
|
al lado de la variable dentro de corchetes [].
|
|
|
|
|
|
<emphasis>sectionelse</emphasis> es ejecutado cuando no hubiera valores
|
|
|
|
|
|
para la variable del loop(ciclo).
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>section</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$data = array(1000,1001,1002);
|
|
|
|
|
|
$smarty->assign('custid',$data);
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{* this example will print out all the values of the $custid array *}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{section name=customer loop=$custid}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
id: {$custid[customer]}<br />
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{/section}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<hr />
|
|
|
|
|
|
{* print out all the values of the $custid array reversed *}
|
|
|
|
|
|
{section name=foo loop=$custid step=-1}
|
|
|
|
|
|
{$custid[foo]}<br />
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
The above example will output:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
id: 1000<br />
|
|
|
|
|
|
id: 1001<br />
|
|
|
|
|
|
id: 1002<br />
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
id: 1002<br />
|
|
|
|
|
|
id: 1001<br />
|
|
|
|
|
|
id: 1000<br />
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Otro par de ejemplos sin un arreglo asignado.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{section name=foo start=10 loop=20 step=2}
|
|
|
|
|
|
{$smarty.section.foo.index}
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
{section name=bar loop=21 max=6 step=-2}
|
|
|
|
|
|
{$smarty.section.bar.index}
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Esta es la salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
10 12 14 16 18
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
20 18 16 14 12 10
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</example>
|
|
|
|
|
|
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>loop(ciclo) de la variable section</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$id = array(1001,1002,1003);
|
|
|
|
|
|
$smarty->assign('custid',$id);
|
|
|
|
|
|
|
|
|
|
|
|
$fullnames = array('John Smith','Jack Jones','Jane Munson');
|
|
|
|
|
|
$smarty->assign('name',$fullnames);
|
|
|
|
|
|
|
|
|
|
|
|
$addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');
|
|
|
|
|
|
$smarty->assign('address',$addr);
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{* la variable del loop solo determina el n<>mero de veces del ciclo.
|
|
|
|
|
|
Usted puede accesar a cualquier variable del template dentro de la section.
|
|
|
|
|
|
Este ejemplo asume que $custid, $name y $address son todas matrizes
|
|
|
|
|
|
conteniendo el mismo n<>mero de valores *}
|
|
|
|
|
|
{section name=customer loop=$custid}
|
|
|
|
|
|
id: {$custid[customer]}<br>
|
|
|
|
|
|
name: {$name[customer]}<br>
|
|
|
|
|
|
address: {$address[customer]}<br>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
{/section}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
La salida del ajemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<p>
|
|
|
|
|
|
id: 1000<br />
|
|
|
|
|
|
name: John Smith<br />
|
|
|
|
|
|
address: 253 N 45th
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
id: 1001<br />
|
|
|
|
|
|
name: Jack Jones<br />
|
|
|
|
|
|
address: 417 Mulberry ln
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
id: 1002<br />
|
|
|
|
|
|
name: Jane Munson<br />
|
|
|
|
|
|
address: 5605 apple st
|
|
|
|
|
|
</p>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>Nombres de section</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{*
|
|
|
|
|
|
El nombre de la section puede ser el que usted quiera,
|
|
|
|
|
|
y es usado para referenciar los datos dentro de una section
|
|
|
|
|
|
*}
|
|
|
|
|
|
{section name=anything loop=$custid}
|
|
|
|
|
|
<p>
|
|
|
|
|
|
id: {$custid[anything]}<br />
|
|
|
|
|
|
name: {$name[anything]}<br />
|
|
|
|
|
|
address: {$address[anything]}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<example>
|
|
|
|
|
|
<title>sections anidadas</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$id = array(1001,1002,1003);
|
|
|
|
|
|
$smarty->assign('custid',$id);
|
|
|
|
|
|
|
|
|
|
|
|
$fullnames = array('John Smith','Jack Jones','Jane Munson');
|
|
|
|
|
|
$smarty->assign('name',$fullnames);
|
|
|
|
|
|
|
|
|
|
|
|
$addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');
|
|
|
|
|
|
$smarty->assign('address',$addr);
|
|
|
|
|
|
|
|
|
|
|
|
$types = array(
|
|
|
|
|
|
array( 'home phone', 'cell phone', 'e-mail'),
|
|
|
|
|
|
array( 'home phone', 'web'),
|
|
|
|
|
|
array( 'cell phone')
|
|
|
|
|
|
);
|
|
|
|
|
|
$smarty->assign('contact_type', $types);
|
|
|
|
|
|
|
|
|
|
|
|
$info = array(
|
|
|
|
|
|
array('555-555-5555', '666-555-5555', 'john@myexample.com'),
|
|
|
|
|
|
array( '123-456-4', 'www.example.com'),
|
|
|
|
|
|
array( '0457878')
|
|
|
|
|
|
);
|
|
|
|
|
|
$smarty->assign('contact_info', $info);
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<programlisting>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<![CDATA[
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{* Las sections pueden ser anidados tan profundamente como usted quiera.
|
|
|
|
|
|
Con las sections anidadas, usted puede accesar a estructuras complejas,
|
|
|
|
|
|
como una matriz multi-dimensional. En este ejemplo, $contact_type[customer]
|
|
|
|
|
|
es una matriz de tipos de contacto para el cliente actual. *}
|
|
|
|
|
|
{section name=customer loop=$custid}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<hr>
|
|
|
|
|
|
id: {$custid[customer]}<br />
|
|
|
|
|
|
name: {$name[customer]}<br />
|
|
|
|
|
|
address: {$address[customer]}<br />
|
|
|
|
|
|
{section name=contact loop=$contact_type[customer]}
|
|
|
|
|
|
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br />
|
|
|
|
|
|
{/section}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{/section}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
la salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
id: 1000<br />
|
|
|
|
|
|
name: John Smith<br />
|
|
|
|
|
|
address: 253 N 45th<br />
|
|
|
|
|
|
home phone: 555-555-5555<br />
|
|
|
|
|
|
cell phone: 666-555-5555<br />
|
|
|
|
|
|
e-mail: john@myexample.com<br />
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
id: 1001<br />
|
|
|
|
|
|
name: Jack Jones<br />
|
|
|
|
|
|
address: 417 Mulberry ln<br />
|
|
|
|
|
|
home phone: 123-456-4<br />
|
|
|
|
|
|
web: www.example.com<br />
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
id: 1002<br />
|
|
|
|
|
|
name: Jane Munson<br />
|
|
|
|
|
|
address: 5605 apple st<br />
|
|
|
|
|
|
cell phone: 0457878<br />
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>sections y matrices asociativas</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
|
|
array('name' => 'John Smith', 'home' => '555-555-5555',
|
|
|
|
|
|
'cell' => '666-555-5555', 'email' => 'john@myexample.com'),
|
|
|
|
|
|
array('name' => 'Jack Jones', 'home' => '777-555-5555',
|
|
|
|
|
|
'cell' => '888-555-5555', 'email' => 'jack@myexample.com'),
|
|
|
|
|
|
array('name' => 'Jane Munson', 'home' => '000-555-5555',
|
|
|
|
|
|
'cell' => '123456', 'email' => 'jane@myexample.com')
|
|
|
|
|
|
);
|
|
|
|
|
|
$smarty->assign('contacts',$data);
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{*
|
|
|
|
|
|
Este es un ejemplo que muestra los datos de una matriz asociativa
|
|
|
|
|
|
dentro de una section
|
|
|
|
|
|
*}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{section name=customer loop=$contacts}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<p>
|
|
|
|
|
|
name: {$contacts[customer].name}<br />
|
|
|
|
|
|
home: {$contacts[customer].home}<br />
|
|
|
|
|
|
cell: {$contacts[customer].cell}<br />
|
|
|
|
|
|
e-mail: {$contacts[customer].email}
|
|
|
|
|
|
</p>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{/section}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Esta es la salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<p>
|
|
|
|
|
|
name: John Smith<br />
|
|
|
|
|
|
home: 555-555-5555<br />
|
|
|
|
|
|
cell: 666-555-5555<br />
|
|
|
|
|
|
e-mail: john@myexample.com
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
name: Jack Jones<br />
|
|
|
|
|
|
home phone: 777-555-5555<br />
|
|
|
|
|
|
cell phone: 888-555-5555<br />
|
|
|
|
|
|
e-mail: jack@myexample.com
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
name: Jane Munson<br />
|
|
|
|
|
|
home phone: 000-555-5555<br />
|
|
|
|
|
|
cell phone: 123456<br />
|
|
|
|
|
|
e-mail: jane@myexample.com
|
|
|
|
|
|
</p>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
<para>Ejemplo usando una base de datos(eg usando Pear o Adodb)</para>
|
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$sql = 'select id, name, home, cell, email from contacts';
|
|
|
|
|
|
$smarty->assign('contacts',$db->getAll($sql) );
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{*
|
|
|
|
|
|
salida de la base de datos, resultado en una tabla
|
|
|
|
|
|
*}
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tr><th> </th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr>
|
|
|
|
|
|
{section name=co loop=$contacts}
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td><a href="view.php?id={$contacts[co].id}">view<a></td>
|
|
|
|
|
|
<td>{$contacts[co].name}</td>
|
|
|
|
|
|
<td>{$contacts[co].home}</td>
|
|
|
|
|
|
<td>{$contacts[co].cell}</td>
|
|
|
|
|
|
<td>{$contacts[co].email}</td>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
</table>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<example>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<title>{sectionelse}</title>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{* sectionelse se ejecutara si no hubieran valores en $custid *}
|
|
|
|
|
|
{section name=customer loop=$custid}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
id: {$custid[customer]}<br />
|
2004-10-07 18:50:52 +00:00
|
|
|
|
{sectionelse}
|
2005-11-08 23:37:29 +00:00
|
|
|
|
there are no values in $custid.
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<para>
|
|
|
|
|
|
Las sections tambi<62>n tiene sus propias variables que manipulan las
|
|
|
|
|
|
propiedades de section. Estas son indicadas asi:
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<link linkend="language.variables.smarty.loops">{$smarty.section.sectionname.varname}</link>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
<note>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
NOTA: a partir de Smarty 1.5.0, la sintaxis de las variables de las
|
|
|
|
|
|
propiedades de section ha sido cambiadas de {%sectionname.varname%} a
|
|
|
|
|
|
{$smarty.section.sectionname.varname}. La sintaxis antigua es aun
|
|
|
|
|
|
soportada, pero usted puede ver la referencia de la sintaxis nueva
|
|
|
|
|
|
en los ejemplos del manual.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</note>
|
|
|
|
|
|
<sect2 id="section.property.index">
|
|
|
|
|
|
<title>index</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
index es usado para mostrar el <20>ndice actual del cliclo(loop), comenzando
|
|
|
|
|
|
en cero (o comienza con el atributo dado), e incrementando por uno (o por
|
|
|
|
|
|
un atributo de paso dado).
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<note>
|
|
|
|
|
|
<title>Nota Tecnica</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Si las propiedades de paso y comienzo del section son modificadas,
|
2005-11-08 23:37:29 +00:00
|
|
|
|
entonces estas funcionan igual a las propiedades de
|
|
|
|
|
|
<link linkend="section.property.iteration">iteration</link> de la
|
2004-10-07 18:50:52 +00:00
|
|
|
|
section, exepto que comienzan en 0 en vez de 1.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</note>
|
|
|
|
|
|
<example>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<title>{section} propiedades del index</title>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{* FYI, $custid[customer.index] y $custid[customer] are identical in meaning *}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
{section name=customer loop=$custid}
|
|
|
|
|
|
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
0 id: 1000<br />
|
|
|
|
|
|
1 id: 1001<br />
|
|
|
|
|
|
2 id: 1002<br />
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect2>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<sect2 id="section.property.index.prev">
|
|
|
|
|
|
<title>index_prev</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
El index_prev es usado para mostrar el <20>ndice anterior del loop(ciclo).
|
|
|
|
|
|
del primer loop(ciclo) esto es definido como -1.
|
|
|
|
|
|
</para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
</sect2>
|
|
|
|
|
|
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<sect2 id="section.property.index.next">
|
|
|
|
|
|
<title>index_next</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
El index_next es usado para mostrar el pr<70>ximo indice del loop.
|
|
|
|
|
|
del <20>ltimo loop, esto es uno mas que el <20>ndice actual( respetando
|
|
|
|
|
|
la definici<63>n del atributo step que se a dado.)
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<title>{section} propiedades del index_next y index_prev</title>
|
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$data = array(1001,1002,1003,1004,1005);
|
|
|
|
|
|
$smarty->assign('custid',$data);
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</programlisting>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{* FYI, $custid[cus.index] and $custid[cus] are identical in meaning *}
|
|
|
|
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th>index</th><th>id</th>
|
|
|
|
|
|
<th>index_prev</th><th>prev_id</th>
|
|
|
|
|
|
<th>index_next</th><th>next_id</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{section name=cus loop=$custid}
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>{$smarty.section.cus.index}</td><td>{$custid[cus]}</td>
|
|
|
|
|
|
<td>{$smarty.section.cus.index_prev}</td><td>{$custid[cus.index_prev]}</td>
|
|
|
|
|
|
<td>{$smarty.section.cus.index_next}</td><td>{$custid[cus.index_next]}</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
</table>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
la salida del ejemplo de arriba esta contenido en la siguiente tabla:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
index id index_prev prev_id index_next next_id
|
|
|
|
|
|
0 1001 -1 1 1002
|
|
|
|
|
|
1 1002 0 1001 2 1003
|
|
|
|
|
|
2 1003 1 1002 3 1004
|
|
|
|
|
|
3 1004 2 1003 4 1005
|
|
|
|
|
|
4 1005 3 1004 5
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<sect2 id="section.property.iteration">
|
|
|
|
|
|
<title>iteration</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
iteration es usado para mostrar la iteraci<63>n actual del loop(ciclo).
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<note>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Esto no es afectado por las propiedades del section start, step y max,
|
2005-11-08 23:37:29 +00:00
|
|
|
|
distinto de las propriedades del <link linkend="section.property.index">index</link>.
|
|
|
|
|
|
Iteration tambi<62>n comineza con 1 en vez de 0 como index.
|
|
|
|
|
|
<link linkend="section.property.rownum">rownum</link> es un alias de iteration,
|
|
|
|
|
|
estas funcionan de manera identica.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
</note>
|
|
|
|
|
|
<example>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<title>{section} propiedades de iteration</title>
|
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
// array of 3000 to 3015
|
|
|
|
|
|
$id = range(3000,3015);
|
|
|
|
|
|
$smarty->assign('custid',$id);
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</programlisting>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{section name=cu loop=$custid start=5 step=2}
|
|
|
|
|
|
iteration={$smarty.section.cu.iteration}
|
|
|
|
|
|
index={$smarty.section.cu.index}
|
|
|
|
|
|
id={$custid[cu]}<br />
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
iteration=1 index=5 id=3005<br />
|
|
|
|
|
|
iteration=2 index=7 id=3007<br />
|
|
|
|
|
|
iteration=3 index=9 id=3009<br />
|
|
|
|
|
|
iteration=4 index=11 id=3011<br />
|
|
|
|
|
|
iteration=5 index=13 id=3013<br />
|
|
|
|
|
|
iteration=6 index=15 id=3015<br />
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Este ejemplo utiliza la propiedad iteration para salida a una tabla
|
|
|
|
|
|
bloqueando el encabezado para cada 5 renglones
|
|
|
|
|
|
(utilice <link linkend="language.function.if">{if}</link> con el operador mod).
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<table>
|
|
|
|
|
|
{section name=co loop=$contacts}
|
|
|
|
|
|
{if $smarty.section.co.iteration % 5 == 1}
|
|
|
|
|
|
<tr><th> </th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td><a href="view.php?id={$contacts[co].id}">view<a></td>
|
|
|
|
|
|
<td>{$contacts[co].name}</td>
|
|
|
|
|
|
<td>{$contacts[co].home}</td>
|
|
|
|
|
|
<td>{$contacts[co].cell}</td>
|
|
|
|
|
|
<td>{$contacts[co].email}</td>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
</table>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<sect2 id="section.property.first">
|
|
|
|
|
|
<title>first</title>
|
|
|
|
|
|
<para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
first es definido como true se la
|
|
|
|
|
|
<link linkend="section.property.iteration">iteraci<EFBFBD>n</link>
|
|
|
|
|
|
actual de la section es la primera.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
</sect2>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<sect2 id="section.property.last">
|
|
|
|
|
|
<title>last</title>
|
|
|
|
|
|
<para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
last es definido como true si la
|
|
|
|
|
|
<link linkend="section.property.iteration">iteraci<EFBFBD>n</link>
|
|
|
|
|
|
actual del section es la ultima.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<example>
|
|
|
|
|
|
<title>{section} propiedades first y last</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
En este ciclo de ejemplo el arreglo $customer, en la salida es bloqueado
|
|
|
|
|
|
el encabezado en la primera iteracion y en la ultima la salida es bloqueda
|
|
|
|
|
|
para el pie de pagina.
|
|
|
|
|
|
(Utilice la propiedad section <link linkend="section.property.total">total</link>)
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{section name=customer loop=$customers}
|
|
|
|
|
|
{if $smarty.section.customer.first}
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tr><th>id</th><th>customer</th></tr>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>{$customers[customer].id}}</td>
|
|
|
|
|
|
<td>{$customers[customer].name}</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
{if $smarty.section.customer.last}
|
|
|
|
|
|
<tr><td></td><td>{$smarty.section.customer.total} customers</td></tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/section}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect2>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<sect2 id="section.property.rownum">
|
|
|
|
|
|
<title>rownum</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
rownum es usado para mostrar la interaci<63>n actual del loop(ciclo),
|
2005-11-08 23:37:29 +00:00
|
|
|
|
comenzando con 1. Es un alias para
|
|
|
|
|
|
<link linkend="section.property.iteration">iteration</link>, estas
|
|
|
|
|
|
funcionan de modo identico.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<sect2 id="section.property.loop">
|
|
|
|
|
|
<title>loop</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
loop es usado para mostrar el ultimo n<>mero del <20>ndice del
|
|
|
|
|
|
loop(ciclo) de esta section. Esto puede ser usado dentro o fuera del section.
|
|
|
|
|
|
</para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<example>
|
|
|
|
|
|
<title>{section} propiedades de index</title>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{section name=customer loop=$custid}
|
|
|
|
|
|
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
|
|
|
|
|
{/section}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
There were {$smarty.section.customer.loop} customers shown above.
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
La salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
0 id: 1000<br />
|
|
|
|
|
|
1 id: 1001<br />
|
|
|
|
|
|
2 id: 1002<br />
|
|
|
|
|
|
|
|
|
|
|
|
There were 3 customers shown above.
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</sect2>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
|
2004-10-07 18:50:52 +00:00
|
|
|
|
<sect2 id="section.property.show">
|
|
|
|
|
|
<title>show</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
<emphasis>show</emphasis>Es usado como par<61>metro para section.
|
|
|
|
|
|
<emphasis>show</emphasis> Es un valor booleano, true o false.
|
|
|
|
|
|
Si es false, la section no ser<65> mostrada. Si existiera un
|
|
|
|
|
|
sectionelse presente, este ser<65> alternativamente mostrado.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>section atributos de show</title>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{*
|
|
|
|
|
|
$show_customer_info debe ser pasado de la aplicacion PHP,
|
|
|
|
|
|
para regular cuando mostrar o no esta section shows
|
|
|
|
|
|
*}
|
|
|
|
|
|
{section name=customer loop=$custid show=$show_customer_info}
|
|
|
|
|
|
{$smarty.section.customer.rownum} id: {$custid[customer]}<br />
|
|
|
|
|
|
{/section}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
{if $smarty.section.customer.show}
|
|
|
|
|
|
the section was shown.
|
|
|
|
|
|
{else}
|
|
|
|
|
|
the section was not shown.
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
La salida del ejemplo de arriba:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
1 id: 1000<br />
|
|
|
|
|
|
2 id: 1001<br />
|
|
|
|
|
|
3 id: 1002<br />
|
|
|
|
|
|
|
|
|
|
|
|
the section was shown.
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect2>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
<sect2 id="section.property.total">
|
|
|
|
|
|
<title>total</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
total es usado para mostrar el n<>mero de iteraciones que est<73>
|
|
|
|
|
|
section tendra. Este puede ser usado dentro o fuera del section.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<title>{section} propiedades de total</title>
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
{section name=customer loop=$custid step=2}
|
|
|
|
|
|
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
|
|
|
|
|
{/section}
|
2004-10-07 18:50:52 +00:00
|
|
|
|
|
2005-11-08 23:37:29 +00:00
|
|
|
|
There were {$smarty.section.customer.total} customers shown above.
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
The above example will output:
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<screen>
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
0 id: 1000<br />
|
|
|
|
|
|
2 id: 1002<br />
|
|
|
|
|
|
4 id: 1004<br />
|
|
|
|
|
|
|
|
|
|
|
|
There were 3 customers shown above.
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</screen>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Ver tambi<62>n <link linkend="language.function.foreach">{foreach}</link>
|
|
|
|
|
|
y <link linkend="language.variables.smarty.loops">$smarty.section</link>.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
</sect2>
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</sect1>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
|
2004-10-07 18:50:52 +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
|
|
|
|
|
|
-->
|