Files
smarty/docs/pt_BR/designers/language-builtin-functions/language-function-section.xml

568 lines
17 KiB
XML
Raw Normal View History

2004-04-13 08:46:28 +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>Nome do atributo</entry>
<entry>Tipo</entry>
<entry>Requerido</entry>
<entry>Padr<EFBFBD>o</entry>
<entry>Descri<EFBFBD><EFBFBD>o</entry>
</row>
</thead>
<tbody>
<row>
<entry>name</entry>
<entry>string</entry>
<entry>Sim</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>O nome da se<73><65>o</entry>
</row>
<row>
<entry>loop</entry>
<entry>[$variable_name]</entry>
<entry>Sim</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>O nome da vari<72>vel para determinar o
n<>mero de intera<72><61>es</entry>
</row>
<row>
<entry>start</entry>
<entry>integer</entry>
<entry>N<EFBFBD>o</entry>
<entry><emphasis>0</emphasis></entry> <entry>A posi<73><69>o
do <20>ndice que a se<73><65>o vai come<6D>ar. Se o valor
<09> negativo, a posi<73><69>o de inicio <20> calculada a partir
do final da matriz. For exemplo, se houverem
sete valores na matriz e start for -2, o
<09>ndice inicial <20> 5. Valores inv<6E>lidos (valores fora do
tamanho da matriz) s<>o automaticamente truncados
para o valor v<>lido mais pr<70>ximo.</entry>
</row>
<row>
<entry>step</entry>
<entry>integer</entry>
<entry>N<EFBFBD>o</entry>
<entry><emphasis>1</emphasis></entry>
<entry>O valor do passo que ser<65> usado para o loop
na matriz. Por exemplo, step=2 ir<69> realizar o loop com
os <20>ndices 0,2,4, etc. Se step for negativo, ele ir<69> caminhar
pela matriz de tr<74>s para frente.</entry>
</row>
<row>
<entry>max</entry>
<entry>integer</entry>
<entry>N<EFBFBD>o</entry>
<entry><emphasis>1</emphasis></entry>
<entry>Define o n<>mero m<>ximo de loops
para a section.</entry>
</row>
<row>
<entry>show</entry>
<entry>boolean</entry>
<entry>N<EFBFBD>o</entry>
<entry><emphasis>true</emphasis></entry>
<entry>Determina quando mostrar ou n<>o esta section</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
sections de template s<>o usada para realizar um loop por uma matriz. Todas as tags
<emphasis>section</emphasis> devem ter as suas
<emphasis>/section</emphasis>. Par<61>metros requeridos s<>o
<emphasis>name</emphasis> e <emphasis>loop</emphasis>. O nome
de section pode ser o que voc<6F> quiser, feito de letras,
n<>meros e sublinhados. Sections podem ser aninhadas, e os nomes das section
aninhadas devem ser diferentes um dos outros. A vari<72>vel do loop
(normalmente uma matriz de valores) determina o n<>mero de vezes do
loop da section. Quando estiver mostrando uma vari<72>vel dentro de uma section,
o nome da section deve estar ao lado da vari<72>vel dentro de conchetes
[]. <emphasis>sectionelse</emphasis> <20>
executado quando n<>o houverem valores para a vari<72>vel de loop.
</para>
<example>
<title>section</title>
<programlisting>
{* este exemplo ir<69> mostrar todos os valores de $custid array *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{/section}
MOSTRA:
id: 1000&lt;br&gt;
id: 1001&lt;br&gt;
id: 1002&lt;br&gt;</programlisting>
</example>
<example>
<title>loop de vari<72>vel section</title>
<programlisting>
{* a vari<72>vel de loo<6F>p determina o n<>mero de vezes do loop.
Voc<6F> pode acessar qualquer vari<72>vel do template dentro da section.
Este exemplo assume que $custid, $name e $address s<>o todas
matrizes contendo o mesmo 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}
MOSTRA:
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>Nomes de section</title>
<programlisting>
{* o nome de section pode ser o que voc<6F> quiser,
e <20> usado para referenciar os dados dentro da 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 aninhadas</title>
<programlisting>
{* sections podem ser aninhadas t<>o profundamente quanto voc<6F> quiser. Com sections aninhadas,
voc<6F> pode acessar estruturas de dados complexas, como matriz multi-dimensionais.
Neste exemplo, $contact_type[customer] <20> uma matriz de
tipos de contato para o custumer atual. *}
{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}
MOSTRA:
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 e matrizes associativas</title>
<programlisting>
{* Este <20> um exemplo de mostrar os dados de matriz associativa
dentro da 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}
MOSTRA:
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 ir<69> executar se n<>o houverem mais valores $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{sectionelse}
there are no values in $custid.
{/section}</programlisting>
</example>
<para>
Sections tamb<6D>m tem as suas pr<70>prias vari<72>veis que manipulam as propriedaes section.
Estas s<>o indicadas assim: {$smarty.section.sectionname.varname}
</para>
<para>
NOTA: a partir do Smarty 1.5.0, a sintaxe para as vari<72>veis de propriedades de section
mudou de {%sectionname.varname%} para
{$smarty.section.sectionname.varname}. A sintaxe antiga ainda <20> suportada,
mas voc<6F> ir<69> ver referencias apenas a nova sintaxe nos
exemplos do manual.
</para>
<sect2 id="section.property.index">
<title>index</title>
<para>
index <20> usado para mostrar o <20>ndice atual do loop, come<6D>ando em zero
(ou pelo atributo start se dado), e incrementando por um (ou pelo
atributo step se dado).
</para>
<note>
<title>Nota T<>cnica</title>
<para>
Se as propriedades section n<>o for modificada,
ent<6E>o isto funciona igual a propriedade iteration da section,
exceto que come<6D>a em 0 ao inv<6E>s de 1.
</para>
</note>
<example>
<title>section property index</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
MOSTRA:
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>
index_prev <20> usado para mostrar o <20>ndice anterior do loop.
No primeiro loop, isto <20> definido como -1.
</para>
<example>
<title>section property 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}
MOSTRA:
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>
index_next <20> usado para mostrar o pr<70>ximo indice do loop. No <20>ltimo loop,
isto ainda <20> um mais o <20>ndice atual( respeitando a defini<6E><69>o
do atributo step, se dado.)
</para>
<example>
<title>section property 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}
MOSTRA:
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 <20> usado para mostrar a intera<72><61>o atual do loop.
</para>
<para>
NOTA: isto n<>o <20> afetado pelas propriedades start, step e
max, diferentemente das propriedade index. Iteration tamb<6D>m come<6D>a com 1
ao inv<6E>s de 0 como index. rownum <20> um apelido para iteration,
elas funcionam de modo identico.
</para>
<example>
<title>section property 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}
MOSTRA:
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 <20> definido como true se a intera<72><61>o atual da section
<20> a primeira.
</para>
<example>
<title>section property 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}
MOSTRA:
&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 <20> definido como true de a intera<72><61>o atual da
section <20> a <20>ltima.
</para>
<example>
<title>section property 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}
MOSTRA:
&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 <20> usado para mostrar a intera<72><61>o atual do loop,
come<6D>ando em um. <20> um apelido para iteration,
elas funcionam de modo identico.
</para>
<example>
<title>section property rownum</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.rownum} id: {$custid[customer]}&lt;br&gt;
{/section}
MOSTRA:
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 <20> usado para mostrar o <20>ltimo n<>mero do <20>ndice do loop desta
section. Isto pode ser usado dentro ou depois de section.
</para>
<example>
<title>section property 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.
MOSTRA:
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> <20> usado como par<61>metro para section.
<emphasis>show</emphasis> <20> um valor booleano, true ou false. Se
false, a section n<>o ser<65> mostrada. Se existir um sectionelse
presente, esta ser<65> alternativamente mostrado.
</para>
<example>
<title>section attribute show</title>
<programlisting>
{* $show_customer_info deve ser passada da aplica<63><61>o PHP,
para regular quando mostrar ou n<>o mostrar esta section *}
{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}
MOSTRA:
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 <20> usado para mostrar o n<>mero de intera<72><61>es que esta section ter<65>.
Isto pode ser usado dentro ou depois da section.
</para>
<example>
<title>section property 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.
MOSTRA:
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
-->