Files
smarty/docs/es/designers/language-builtin-functions/language-function-section.xml
2004-10-07 18:50:52 +00:00

572 lines
17 KiB
XML

<?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ó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>
<entry>[$variable_name]</entry>
<entry>Si</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>El nombre de la variable para determinar el número de
iteracciones</entry>
</row>
<row>
<entry>start</entry>
<entry>integer</entry>
<entry>No</entry>
<entry><emphasis>0</emphasis></entry>
<entry> La posición del índice de la section donde va a comenzar.
Si el valor es negativo, la posició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 índice inicial es 5.
Valores inválidos (valores fuera del tamaño de la matriz) son
automáticamente truncados para el valor valido mas pró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 í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í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ón</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Las section del template son usada para realizar un ciclo(loop) de
un arreglo de datos. Todas las etiquetas <emphasis>section</emphasis>
deben tener su par <emphasis>/section</emphasis>. Los pará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>
<programlisting>
{* este ejemplo muestra todos los valores del arreglo $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{/section}
SALIDA:
id: 1000&lt;br&gt;
id: 1001&lt;br&gt;
id: 1002&lt;br&gt;</programlisting>
</example>
<example>
<title>loop(ciclo) de la variable section</title>
<programlisting>
{* 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]}&lt;br&gt;
name: {$name[customer]}&lt;br&gt;
address: {$address[customer]}&lt;br&gt;
&lt;p&gt;
{/section}
SALIDA:
id: 1000&lt;br&gt;
name: John Smith&lt;br&gt;
address: 253 N 45th&lt;br&gt;
&lt;p&gt;
id: 1001&lt;br&gt;
name: Jack Jones&lt;br&gt;
address: 417 Mulberry ln&lt;br&gt;
&lt;p&gt;
id: 1002&lt;br&gt;
name: Jane Munson&lt;br&gt;
address: 5605 apple st&lt;br&gt;
&lt;p&gt;</programlisting>
</example>
<example>
<title>Nombres de section</title>
<programlisting>
{* El nombre de la section puede ser el que usted quiera,
y es usado para referenciar los datos dentro de una section *}
{section name=mydata loop=$custid}
id: {$custid[mydata]}&lt;br&gt;
name: {$name[mydata]}&lt;br&gt;
address: {$address[mydata]}&lt;br&gt;
&lt;p&gt;
{/section}</programlisting>
</example>
<example>
<title>sections anidadas</title>
<programlisting>
{* 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}
id: {$custid[customer]}&lt;br&gt;
name: {$name[customer]}&lt;br&gt;
address: {$address[customer]}&lt;br&gt;
{section name=contact loop=$contact_type[customer]}
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}&lt;br&gt;
{/section}
&lt;p&gt;
{/section}
SALIDA:
id: 1000&lt;br&gt;
name: John Smith&lt;br&gt;
address: 253 N 45th&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: john@mydomain.com&lt;br&gt;
&lt;p&gt;
id: 1001&lt;br&gt;
name: Jack Jones&lt;br&gt;
address: 417 Mulberry ln&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@mydomain.com&lt;br&gt;
&lt;p&gt;
id: 1002&lt;br&gt;
name: Jane Munson&lt;br&gt;
address: 5605 apple st&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@mydomain.com&lt;br&gt;
&lt;p&gt;</programlisting>
</example>
<example>
<title>sections y matrices asociativas</title>
<programlisting>
{* Este es un ejemplo que muestra los datos de una matriz asociativa
dentro de una section *}
{section name=customer loop=$contacts}
name: {$contacts[customer].name}&lt;br&gt;
home: {$contacts[customer].home}&lt;br&gt;
cell: {$contacts[customer].cell}&lt;br&gt;
e-mail: {$contacts[customer].email}&lt;p&gt;
{/section}
SALIDA:
name: John Smith&lt;br&gt;
home: 555-555-5555&lt;br&gt;
cell: 555-555-5555&lt;br&gt;
e-mail: john@mydomain.com&lt;p&gt;
name: Jack Jones&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@mydomain.com&lt;p&gt;
name: Jane Munson&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@mydomain.com&lt;p&gt;</programlisting>
</example>
<example>
<title>sectionelse</title>
<programlisting>
{* sectionelse se ejecutara si no hubieran valores en $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{sectionelse}
there are no values in $custid.
{/section}</programlisting>
</example>
<para>
Las sections también tiene sus propias variables que manipulan las
propiedades de section. Estas son indicadas asi:
{$smarty.section.sectionname.varname}
</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 í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,
entonces estas funcionan igual a las propiedades de iteration de la
section, exepto que comienzan en 0 en vez de 1.
</para>
</note>
<example>
<title> section propiedades del index</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
SALIDA:
0 id: 1000&lt;br&gt;
1 id: 1001&lt;br&gt;
2 id: 1002&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.index.prev">
<title>index_prev</title>
<para>
El index_prev es usado para mostrar el índice anterior del loop(ciclo).
del primer loop(ciclo) esto es definido como -1.
</para>
<example>
<title>section propiedades del index_prev</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
{if $custid[customer.index_prev] ne $custid[customer.index]}
The customer id changed&lt;br&gt;
{/if}
{/section}
SALIDA:
0 id: 1000&lt;br&gt;
The customer id changed&lt;br&gt;
1 id: 1001&lt;br&gt;
The customer id changed&lt;br&gt;
2 id: 1002&lt;br&gt;
The customer id changed&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.index.next">
<title>index_next</title>
<para>
El index_next es usado para mostrar el próximo indice del loop.
del último loop, esto es uno mas que el índice actual( respetando
la definición del atributo step que se a dado.)
</para>
<example>
<title>section propiedades del index_next</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
{if $custid[customer.index_next] ne $custid[customer.index]}
The customer id will change&lt;br&gt;
{/if}
{/section}
SALIDA:
0 id: 1000&lt;br&gt;
The customer id will change&lt;br&gt;
1 id: 1001&lt;br&gt;
The customer id will change&lt;br&gt;
2 id: 1002&lt;br&gt;
The customer id will change&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.iteration">
<title>iteration</title>
<para>
iteration es usado para mostrar la iteración actual del loop(ciclo).
</para>
<note>
<para>
Esto no es afectado por las propiedades del section start, step y max,
distinto de las propriedades del index. Iteration también comineza con
1 en vez de 0 como index. rownum es un alias de iteration, estas funcionan
de manera identica.
</para>
</note>
<example>
<title>section propiedades de iteration</title>
<programlisting>
{section name=customer loop=$custid start=5 step=2}
current loop iteration: {$smarty.section.customer.iteration}&lt;br&gt;
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
{if $custid[customer.index_next] ne $custid[customer.index]}
The customer id will change&lt;br&gt;
{/if}
{/section}
SALIDA:
current loop iteration: 1
5 id: 1000&lt;br&gt;
The customer id will change&lt;br&gt;
current loop iteration: 2
7 id: 1001&lt;br&gt;
The customer id will change&lt;br&gt;
current loop iteration: 3
9 id: 1002&lt;br&gt;
The customer id will change&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.first">
<title>first</title>
<para>
first es definido como true se la iteración actual de la section es la primera.
</para>
<example>
<title>section propiedades de first</title>
<programlisting>
{section name=customer loop=$custid}
{if $smarty.section.customer.first}
&lt;table&gt;
{/if}
&lt;tr&gt;&lt;td&gt;{$smarty.section.customer.index} id:
{$custid[customer]}&lt;/td&gt;&lt;/tr&gt;
{if $smarty.section.customer.last}
&lt;/table&gt;
{/if}
{/section}
SALIDA:
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;0 id: 1000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1 id: 1001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2 id: 1002&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.last">
<title>last</title>
<para>
last es definido como true si la iteración actual del section es la ultima.
</para>
<example>
<title>section propiedades de last</title>
<programlisting>
{section name=customer loop=$custid}
{if $smarty.section.customer.first}
&lt;table&gt;
{/if}
&lt;tr&gt;&lt;td&gt;{$smarty.section.customer.index} id:
{$custid[customer]}&lt;/td&gt;&lt;/tr&gt;
{if $smarty.section.customer.last}
&lt;/table&gt;
{/if}
{/section}
SALIDA:
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;0 id: 1000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1 id: 1001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2 id: 1002&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.rownum">
<title>rownum</title>
<para>
rownum es usado para mostrar la interación actual del loop(ciclo),
comenzando con 1. Es un alias para iteration, estas funcionan de
modo identico.
</para>
<example>
<title> section propiedades de rownum</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.rownum} id: {$custid[customer]}&lt;br&gt;
{/section}
SALIDA:
1 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
3 id: 1002&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.loop">
<title>loop</title>
<para>
loop es usado para mostrar el ultimo número del índice del
loop(ciclo) de esta section. Esto puede ser usado dentro o fuera del section.
</para>
<example>
<title>section propiedades de index</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
There were {$smarty.section.customer.loop} customers shown above.
SALIDA:
0 id: 1000&lt;br&gt;
1 id: 1001&lt;br&gt;
2 id: 1002&lt;br&gt;
There were 3 customers shown above.
</programlisting>
</example>
</sect2>
<sect2 id="section.property.show">
<title>show</title>
<para>
<emphasis>show</emphasis>Es usado como parámetro para section.
<emphasis>show</emphasis> Es un valor booleano, true o false.
Si es false, la section no será mostrada. Si existiera un
sectionelse presente, este será alternativamente mostrado.
</para>
<example>
<title>section atributos de show</title>
<programlisting>
{* $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]}&lt;br&gt;
{/section}
{if $smarty.section.customer.show}
the section was shown.
{else}
the section was not shown.
{/if}
SALIDA:
1 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
3 id: 1002&lt;br&gt;
the section was shown.
</programlisting>
</example>
</sect2>
<sect2 id="section.property.total">
<title>total</title>
<para>
total es usado para mostrar el número de iteraciones que está
section tendra. Este puede ser usado dentro o fuera del section.
</para>
<example>
<title>section propiedades de total</title>
<programlisting>
{section name=customer loop=$custid step=2}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
There were {$smarty.section.customer.total} customers shown above.
SALIDA:
0 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
4 id: 1002&lt;br&gt;
There were 3 customers shown above.
</programlisting>
</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
-->