mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 13:51:36 +01:00
572 lines
17 KiB
XML
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]}<br>
|
|
{/section}
|
|
|
|
SALIDA:
|
|
|
|
id: 1000<br>
|
|
id: 1001<br>
|
|
id: 1002<br></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]}<br>
|
|
name: {$name[customer]}<br>
|
|
address: {$address[customer]}<br>
|
|
<p>
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
id: 1000<br>
|
|
name: John Smith<br>
|
|
address: 253 N 45th<br>
|
|
<p>
|
|
id: 1001<br>
|
|
name: Jack Jones<br>
|
|
address: 417 Mulberry ln<br>
|
|
<p>
|
|
id: 1002<br>
|
|
name: Jane Munson<br>
|
|
address: 5605 apple st<br>
|
|
<p></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]}<br>
|
|
name: {$name[mydata]}<br>
|
|
address: {$address[mydata]}<br>
|
|
<p>
|
|
{/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]}<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}
|
|
<p>
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
id: 1000<br>
|
|
name: John Smith<br>
|
|
address: 253 N 45th<br>
|
|
home phone: 555-555-5555<br>
|
|
cell phone: 555-555-5555<br>
|
|
e-mail: john@mydomain.com<br>
|
|
<p>
|
|
id: 1001<br>
|
|
name: Jack Jones<br>
|
|
address: 417 Mulberry ln<br>
|
|
home phone: 555-555-5555<br>
|
|
cell phone: 555-555-5555<br>
|
|
e-mail: jack@mydomain.com<br>
|
|
<p>
|
|
id: 1002<br>
|
|
name: Jane Munson<br>
|
|
address: 5605 apple st<br>
|
|
home phone: 555-555-5555<br>
|
|
cell phone: 555-555-5555<br>
|
|
e-mail: jane@mydomain.com<br>
|
|
<p></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}<br>
|
|
home: {$contacts[customer].home}<br>
|
|
cell: {$contacts[customer].cell}<br>
|
|
e-mail: {$contacts[customer].email}<p>
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
name: John Smith<br>
|
|
home: 555-555-5555<br>
|
|
cell: 555-555-5555<br>
|
|
e-mail: john@mydomain.com<p>
|
|
name: Jack Jones<br>
|
|
home phone: 555-555-5555<br>
|
|
cell phone: 555-555-5555<br>
|
|
e-mail: jack@mydomain.com<p>
|
|
name: Jane Munson<br>
|
|
home phone: 555-555-5555<br>
|
|
cell phone: 555-555-5555<br>
|
|
e-mail: jane@mydomain.com<p></programlisting>
|
|
</example>
|
|
|
|
|
|
|
|
<example>
|
|
<title>sectionelse</title>
|
|
<programlisting>
|
|
{* sectionelse se ejecutara si no hubieran valores en $custid *}
|
|
{section name=customer loop=$custid}
|
|
id: {$custid[customer]}<br>
|
|
{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]}<br>
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
0 id: 1000<br>
|
|
1 id: 1001<br>
|
|
2 id: 1002<br>
|
|
</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]}<br>
|
|
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
|
{if $custid[customer.index_prev] ne $custid[customer.index]}
|
|
The customer id changed<br>
|
|
{/if}
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
0 id: 1000<br>
|
|
The customer id changed<br>
|
|
1 id: 1001<br>
|
|
The customer id changed<br>
|
|
2 id: 1002<br>
|
|
The customer id changed<br>
|
|
</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]}<br>
|
|
{* 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<br>
|
|
{/if}
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
0 id: 1000<br>
|
|
The customer id will change<br>
|
|
1 id: 1001<br>
|
|
The customer id will change<br>
|
|
2 id: 1002<br>
|
|
The customer id will change<br>
|
|
</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}<br>
|
|
{$smarty.section.customer.index} id: {$custid[customer]}<br>
|
|
{* 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<br>
|
|
{/if}
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
current loop iteration: 1
|
|
5 id: 1000<br>
|
|
The customer id will change<br>
|
|
current loop iteration: 2
|
|
7 id: 1001<br>
|
|
The customer id will change<br>
|
|
current loop iteration: 3
|
|
9 id: 1002<br>
|
|
The customer id will change<br>
|
|
</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}
|
|
<table>
|
|
{/if}
|
|
|
|
<tr><td>{$smarty.section.customer.index} id:
|
|
{$custid[customer]}</td></tr>
|
|
|
|
{if $smarty.section.customer.last}
|
|
</table>
|
|
{/if}
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
<table>
|
|
<tr><td>0 id: 1000</td></tr>
|
|
<tr><td>1 id: 1001</td></tr>
|
|
<tr><td>2 id: 1002</td></tr>
|
|
</table>
|
|
</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}
|
|
<table>
|
|
{/if}
|
|
|
|
<tr><td>{$smarty.section.customer.index} id:
|
|
{$custid[customer]}</td></tr>
|
|
|
|
{if $smarty.section.customer.last}
|
|
</table>
|
|
{/if}
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
<table>
|
|
<tr><td>0 id: 1000</td></tr>
|
|
<tr><td>1 id: 1001</td></tr>
|
|
<tr><td>2 id: 1002</td></tr>
|
|
</table>
|
|
</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]}<br>
|
|
{/section}
|
|
|
|
|
|
SALIDA:
|
|
|
|
1 id: 1000<br>
|
|
2 id: 1001<br>
|
|
3 id: 1002<br>
|
|
</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]}<br>
|
|
{/section}
|
|
|
|
There were {$smarty.section.customer.loop} customers shown above.
|
|
|
|
SALIDA:
|
|
|
|
0 id: 1000<br>
|
|
1 id: 1001<br>
|
|
2 id: 1002<br>
|
|
|
|
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]}<br>
|
|
{/section}
|
|
|
|
{if $smarty.section.customer.show}
|
|
the section was shown.
|
|
{else}
|
|
the section was not shown.
|
|
{/if}
|
|
|
|
|
|
SALIDA:
|
|
|
|
1 id: 1000<br>
|
|
2 id: 1001<br>
|
|
3 id: 1002<br>
|
|
|
|
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]}<br>
|
|
{/section}
|
|
|
|
There were {$smarty.section.customer.total} customers shown above.
|
|
|
|
SALIDA:
|
|
|
|
0 id: 1000<br>
|
|
2 id: 1001<br>
|
|
4 id: 1002<br>
|
|
|
|
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
|
|
-->
|