mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
* some wz
* no tab * add Cdata section
This commit is contained in:
@@ -73,45 +73,59 @@
|
||||
<example>
|
||||
<title>foreach</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
|
||||
{* this example will print out all the values of the $custid array *}
|
||||
{foreach from=$custid item=curr_id}
|
||||
id: {$curr_id}<br>
|
||||
id: {$curr_id}<br />
|
||||
{/foreach}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
id: 1000<br>
|
||||
id: 1001<br>
|
||||
id: 1002<br></programlisting>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
id: 1000<br />
|
||||
id: 1001<br />
|
||||
id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>foreach key</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* The key contains the key for each looped value
|
||||
|
||||
assignment looks like this:
|
||||
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
|
||||
*}
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$contact}
|
||||
{$key}: {$item}<br>
|
||||
{$key}: {$item}<br />
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
phone: 1<br>
|
||||
fax: 2<br>
|
||||
cell: 3<br>
|
||||
phone: 555-4444<br>
|
||||
fax: 555-3333<br>
|
||||
cell: 760-1234<br></programlisting>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
phone: 1<br />
|
||||
fax: 2<br />
|
||||
cell: 3<br />
|
||||
phone: 555-4444<br />
|
||||
fax: 555-3333<br />
|
||||
cell: 760-1234<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -121,7 +135,6 @@ cell: 760-1234<br></programlisting>
|
||||
attribute of foreach
|
||||
</para>
|
||||
|
||||
|
||||
<sect2 id="foreach.property.iteration">
|
||||
<title>iteration</title>
|
||||
<para>
|
||||
@@ -166,11 +179,6 @@ cell: 760-1234<br></programlisting>
|
||||
will loop. This can be used inside or after the foreach.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
@@ -139,6 +139,7 @@
|
||||
<example>
|
||||
<title>if statements</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{if $name eq "Fred"}
|
||||
Welcome Sir.
|
||||
{elseif $name eq "Wilma"}
|
||||
@@ -165,7 +166,7 @@
|
||||
|
||||
|
||||
{* parenthesis are allowed *}
|
||||
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
|
||||
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
|
||||
...
|
||||
{/if}
|
||||
|
||||
@@ -199,7 +200,9 @@
|
||||
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
|
||||
{if $var is even by 3}
|
||||
...
|
||||
{/if}</programlisting>
|
||||
{/if}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
@@ -94,10 +94,11 @@
|
||||
<example>
|
||||
<title>function include_php</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
load_nav.php
|
||||
-------------
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
// load in variables from a mysql db and assign them to the template
|
||||
require_once("MySQL.class.php");
|
||||
@@ -105,18 +106,22 @@ load_nav.php
|
||||
$sql->query("select * from site_nav_sections order by name",SQL_ALL);
|
||||
$this->assign('sections',$sql->record);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
index.tpl
|
||||
---------
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.pl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* absolute path, or relative to $trusted_dir *}
|
||||
{include_php file="/path/to/load_nav.php"}
|
||||
|
||||
{foreach item="curr_section" from=$sections}
|
||||
<a href="{$curr_section.url}">{$curr_section.name}</a><br>
|
||||
{/foreach}</programlisting>
|
||||
<a href="{$curr_section.url}">{$curr_section.name}</a><br />
|
||||
{/foreach}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
@@ -138,4 +143,3 @@ End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
@@ -91,146 +91,174 @@
|
||||
<example>
|
||||
<title>section</title>
|
||||
<programlisting>
|
||||
|
||||
<![CDATA[
|
||||
{* this example will print out all the values of the $custid array *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
id: 1000<br>
|
||||
id: 1001<br>
|
||||
id: 1002<br></programlisting>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
id: 1000<br />
|
||||
id: 1001<br />
|
||||
id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>section loop variable</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* the loop variable only determines the number of times to loop.
|
||||
you can access any variable from the template within the section.
|
||||
This example assumes that $custid, $name and $address are all
|
||||
arrays containing the same number of values *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
name: {$name[customer]}<br>
|
||||
address: {$address[customer]}<br>
|
||||
<p>
|
||||
id: {$custid[customer]}<br />
|
||||
name: {$name[customer]}<br />
|
||||
address: {$address[customer]}<br />
|
||||
<p>
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
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>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>section names</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* the name of the section can be anything you like,
|
||||
and it is used to reference the data within the section *}
|
||||
{section name=mydata loop=$custid}
|
||||
id: {$custid[mydata]}<br>
|
||||
name: {$name[mydata]}<br>
|
||||
address: {$address[mydata]}<br>
|
||||
<p>
|
||||
{/section}</programlisting>
|
||||
id: {$custid[mydata]}<br />
|
||||
name: {$name[mydata]}<br />
|
||||
address: {$address[mydata]}<br />
|
||||
<p>
|
||||
{/section}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>nested sections</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* sections can be nested as deep as you like. With nested sections,
|
||||
you can access complex data structures, such as multi-dimensional
|
||||
arrays. In this example, $contact_type[customer] is an array of
|
||||
contact types for the current customer. *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
name: {$name[customer]}<br>
|
||||
address: {$address[customer]}<br>
|
||||
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>
|
||||
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br />
|
||||
{/section}
|
||||
<p>
|
||||
<p>
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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@myexample.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@myexample.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@myexample.com<br>
|
||||
<p></programlisting>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
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@myexample.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@myexample.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@myexample.com<br />
|
||||
<p>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>sections and associative arrays</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* This is an example of printing an associative array
|
||||
of data within a 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>
|
||||
name: {$contacts[customer].name}<br />
|
||||
home: {$contacts[customer].home}<br />
|
||||
cell: {$contacts[customer].cell}<br />
|
||||
e-mail: {$contacts[customer].email}<p>
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
name: John Smith<br>
|
||||
home: 555-555-5555<br>
|
||||
cell: 555-555-5555<br>
|
||||
e-mail: john@myexample.com<p>
|
||||
name: Jack Jones<br>
|
||||
home phone: 555-555-5555<br>
|
||||
cell phone: 555-555-5555<br>
|
||||
e-mail: jack@myexample.com<p>
|
||||
name: Jane Munson<br>
|
||||
home phone: 555-555-5555<br>
|
||||
cell phone: 555-555-5555<br>
|
||||
e-mail: jane@myexample.com<p></programlisting>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
name: John Smith<br />
|
||||
home: 555-555-5555<br />
|
||||
cell: 555-555-5555<br />
|
||||
e-mail: john@myexample.com<p>
|
||||
name: Jack Jones<br />
|
||||
home phone: 555-555-5555<br />
|
||||
cell phone: 555-555-5555<br />
|
||||
e-mail: jack@myexample.com<p>
|
||||
name: Jane Munson<br />
|
||||
home phone: 555-555-5555<br />
|
||||
cell phone: 555-555-5555<br />
|
||||
e-mail: jane@myexample.com<p>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
|
||||
|
||||
<example>
|
||||
<title>sectionelse</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* sectionelse will execute if there are no $custid values *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
id: {$custid[customer]}<br />
|
||||
{sectionelse}
|
||||
there are no values in $custid.
|
||||
{/section}</programlisting>
|
||||
{/section}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Sections also have their own variables that handle section properties.
|
||||
@@ -263,17 +291,22 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property index</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br>
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
0 id: 1000<br>
|
||||
1 id: 1001<br>
|
||||
2 id: 1002<br>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
0 id: 1000<br />
|
||||
1 id: 1001<br />
|
||||
2 id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.index.prev">
|
||||
@@ -285,24 +318,29 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property index_prev</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br>
|
||||
{$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>
|
||||
The customer id changed<br />
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
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 />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.index.next">
|
||||
@@ -315,24 +353,29 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property index_next</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<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>
|
||||
The customer id will change<br />
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
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 />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.iteration">
|
||||
@@ -351,28 +394,33 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property iteration</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{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>
|
||||
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>
|
||||
The customer id will change<br />
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
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 />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.first">
|
||||
@@ -384,28 +432,33 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property first</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{if $smarty.section.customer.first}
|
||||
<table>
|
||||
<table>
|
||||
{/if}
|
||||
|
||||
<tr><td>{$smarty.section.customer.index} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
<tr><td>{$smarty.section.customer.index} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
|
||||
{if $smarty.section.customer.last}
|
||||
</table>
|
||||
</table>
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.last">
|
||||
@@ -417,28 +470,33 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property last</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{if $smarty.section.customer.first}
|
||||
<table>
|
||||
<table>
|
||||
{/if}
|
||||
|
||||
<tr><td>{$smarty.section.customer.index} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
<tr><td>{$smarty.section.customer.index} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
|
||||
{if $smarty.section.customer.last}
|
||||
</table>
|
||||
</table>
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.rownum">
|
||||
@@ -451,17 +509,22 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property rownum</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{$smarty.section.customer.rownum} id: {$custid[customer]}<br>
|
||||
{$smarty.section.customer.rownum} id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
1 id: 1000<br>
|
||||
2 id: 1001<br>
|
||||
3 id: 1002<br>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
1 id: 1000<br />
|
||||
2 id: 1001<br />
|
||||
3 id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.loop">
|
||||
@@ -473,20 +536,26 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property index</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid}
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br>
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
There were {$smarty.section.customer.loop} customers shown above.
|
||||
|
||||
OUTPUT:
|
||||
|
||||
0 id: 1000<br>
|
||||
1 id: 1001<br>
|
||||
2 id: 1002<br>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
0 id: 1000<br />
|
||||
1 id: 1001<br />
|
||||
2 id: 1002<br />
|
||||
|
||||
There were 3 customers shown above.
|
||||
</programlisting>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.show">
|
||||
@@ -500,10 +569,11 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section attribute show</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* $show_customer_info may have been passed from the PHP
|
||||
application, to regulate whether or not this section shows *}
|
||||
{section name=customer loop=$custid show=$show_customer_info}
|
||||
{$smarty.section.customer.rownum} id: {$custid[customer]}<br>
|
||||
{$smarty.section.customer.rownum} id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
{if $smarty.section.customer.show}
|
||||
@@ -511,16 +581,20 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
{else}
|
||||
the section was not shown.
|
||||
{/if}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
1 id: 1000<br>
|
||||
2 id: 1001<br>
|
||||
3 id: 1002<br>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
1 id: 1000<br />
|
||||
2 id: 1001<br />
|
||||
3 id: 1002<br />
|
||||
|
||||
the section was shown.
|
||||
</programlisting>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="section.property.total">
|
||||
@@ -532,20 +606,26 @@ e-mail: jane@myexample.com<p></programlisting>
|
||||
<example>
|
||||
<title>section property total</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{section name=customer loop=$custid step=2}
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br>
|
||||
{$smarty.section.customer.index} id: {$custid[customer]}<br />
|
||||
{/section}
|
||||
|
||||
There were {$smarty.section.customer.total} customers shown above.
|
||||
|
||||
OUTPUT:
|
||||
|
||||
0 id: 1000<br>
|
||||
2 id: 1001<br>
|
||||
4 id: 1002<br>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
0 id: 1000<br />
|
||||
2 id: 1001<br />
|
||||
4 id: 1002<br />
|
||||
|
||||
There were 3 customers shown above.
|
||||
</programlisting>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
@@ -66,19 +66,22 @@
|
||||
<example>
|
||||
<title>eval</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
setup.conf
|
||||
----------
|
||||
|
||||
emphstart = <b>
|
||||
emphend = </b>
|
||||
emphstart = <strong>
|
||||
emphend = </strong>
|
||||
title = Welcome to {$company}'s home page!
|
||||
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
|
||||
ErrorState = You must supply a {#emphstart#}state{#emphend#}.
|
||||
|
||||
|
||||
index.tpl
|
||||
---------
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{config_load file="setup.conf"}
|
||||
|
||||
{eval var=$foo}
|
||||
@@ -86,15 +89,21 @@ index.tpl
|
||||
{eval var=#ErrorCity#}
|
||||
{eval var=#ErrorState# assign="state_error"}
|
||||
{$state_error}
|
||||
|
||||
OUTPUT:
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
||||
This is the contents of foo.
|
||||
Welcome to Foobar Pub & Grill's home page!
|
||||
You must supply a <b>city</b>.
|
||||
You must supply a <b>state</b>.
|
||||
Welcome to Foobar Pub & Grill's home page!
|
||||
You must supply a <strong>city</strong>.
|
||||
You must supply a <strong>state</strong>.
|
||||
|
||||
</programlisting>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
@@ -70,67 +70,87 @@
|
||||
</para>
|
||||
<para>
|
||||
If the optional <emphasis>name</emphasis> attribute is given, the
|
||||
<select name="groupname"></select> tags will enclose
|
||||
<select name="groupname"></select> tags will enclose
|
||||
the option list. Otherwise only the option list is generated.
|
||||
</para>
|
||||
<para>
|
||||
All parameters that are not in the list above are printed as
|
||||
name/value-pairs inside the <select>-tag. They are ignored if
|
||||
name/value-pairs inside the <select>-tag. They are ignored if
|
||||
the optional <emphasis>name</emphasis> is not given.
|
||||
</para>
|
||||
<example>
|
||||
<title>html_options</title>
|
||||
<title>html_options : Example 1</title>
|
||||
<programlisting>
|
||||
EXAMPLE 1
|
||||
---------
|
||||
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
|
||||
$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
|
||||
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
|
||||
$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
|
||||
Johnson','Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
|
||||
index.tpl:
|
||||
|
||||
<select name=customer_id>
|
||||
<select name=customer_id>
|
||||
{html_options values=$cust_ids selected=$customer_id output=$cust_names}
|
||||
</select>
|
||||
|
||||
EXAMPLE 2
|
||||
---------
|
||||
|
||||
</select>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Example 2
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('cust_options', array(
|
||||
1001 => 'Joe Schmoe',
|
||||
1002 => 'Jack Smith',
|
||||
1003 => 'Jane Johnson',
|
||||
1004 => 'Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
$smarty->assign('cust_options', array(
|
||||
1001 => 'Joe Schmoe',
|
||||
1002 => 'Jack Smith',
|
||||
1003 => 'Jane Johnson',
|
||||
1004 => 'Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
|
||||
index.tpl:
|
||||
|
||||
<select name=customer_id>
|
||||
<select name=customer_id>
|
||||
{html_options options=$cust_options selected=$customer_id}
|
||||
</select>
|
||||
</select>
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Both examples will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
||||
OUTPUT: (both examples)
|
||||
-----------------------
|
||||
<select name=customer_id>
|
||||
<option label="Joe Schmoe" value="1000">Joe Schmoe</option>
|
||||
<option label="Jack Smith" value="1001" selected="selected">Jack Smith</option>
|
||||
<option label="Jane Johnson" value="1002">Jane Johnson</option>
|
||||
<option label="Charlie Brown" value="1003">Charlie Brown</option>
|
||||
</select>
|
||||
|
||||
<select name=customer_id>
|
||||
<option label="Joe Schmoe" value="1000">Joe Schmoe</option>
|
||||
<option label="Jack Smith" value="1001" selected="selected">Jack Smith</option>
|
||||
<option label="Jane Johnson" value="1002">Jane Johnson</option>
|
||||
<option label="Charlie Brown" value="1003">Charlie Brown</option>
|
||||
</select></programlisting>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
@@ -72,54 +72,74 @@
|
||||
</para>
|
||||
<para>
|
||||
All parameters that are not in the list above are printed as
|
||||
name/value-pairs inside each of the created <input>-tags.
|
||||
name/value-pairs inside each of the created <input>-tags.
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>html_radios</title>
|
||||
<title>html_radios : Example 1</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
|
||||
$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
|
||||
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
|
||||
$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
|
||||
Johnson','Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
|
||||
index.tpl:
|
||||
|
||||
{html_radios name="id" values=$cust_ids selected=$customer_id output=$cust_names separator="<br />"}
|
||||
|
||||
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{html_radios name="id" values=$cust_ids selected=$customer_id output=$cust_names separator="<br />"}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Example 2 :
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('cust_radios', array(
|
||||
1000 => 'Joe Schmoe',
|
||||
1001 => 'Jack Smith',
|
||||
1002 => 'Jane Johnson',
|
||||
1003 => 'Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
|
||||
index.tpl:
|
||||
|
||||
{html_radios name="id" options=$cust_radios selected=$customer_id separator="<br />"}
|
||||
|
||||
|
||||
OUTPUT: (both examples)
|
||||
|
||||
<label for="id_1000"><input type="radio" name="id" value="1000" id="id_1000" />Joe Schmoe</label><br />
|
||||
<label for="id_1001"><input type="radio" name="id" value="1001" id="id_1001" checked="checked" />Jack Smith</label><br />
|
||||
<label for="id_1002"><input type="radio" name="id" value="1002" id="id_1002" />Jane Johnson</label><br />
|
||||
<label for="id_1003"><input type="radio" name="id" value="1003" id="id_1003" />Charlie Brown</label><br /></programlisting>
|
||||
$smarty->assign('cust_radios', array(
|
||||
1000 => 'Joe Schmoe',
|
||||
1001 => 'Jack Smith',
|
||||
1002 => 'Jane Johnson',
|
||||
1003 => 'Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{html_radios name="id" options=$cust_radios selected=$customer_id separator="<br />"}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Both examples will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<label for="id_1000"><input type="radio" name="id" value="1000" id="id_1000" />Joe Schmoe</label><br />
|
||||
<label for="id_1001"><input type="radio" name="id" value="1001" id="id_1001" checked="checked" />Jack Smith</label><br />
|
||||
<label for="id_1002"><input type="radio" name="id" value="1002" id="id_1002" />Jane Johnson</label><br />
|
||||
<label for="id_1003"><input type="radio" name="id" value="1003" id="id_1003" />Charlie Brown</label><br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect1>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
|
@@ -105,6 +105,7 @@
|
||||
<example>
|
||||
<title>mailto</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{mailto address="me@example.com"}
|
||||
{mailto address="me@example.com" text="send me some mail"}
|
||||
{mailto address="me@example.com" encode="javascript"}
|
||||
@@ -113,25 +114,30 @@
|
||||
{mailto address="me@example.com" cc="you@example.com,they@example.com"}
|
||||
{mailto address="me@example.com" extra='class="email"'}
|
||||
{mailto address="me@example.com" encode="javascript_charcode"}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<a href="mailto:me@example.com" >me@example.com</a>
|
||||
<a href="mailto:me@example.com" >send me some mail</a>
|
||||
<script type="text/javascript" language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<a href="mailto:me@example.com" >me@example.com</a>
|
||||
<a href="mailto:me@example.com" >send me some mail</a>
|
||||
<script type="text/javascript" language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6
|
||||
9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%
|
||||
61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e
|
||||
%27%29%3b'))</script>
|
||||
<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >me@domain.com</a>
|
||||
<a href="mailto:me@example.com?subject=Hello%20to%20you%21" >me@example.com</a>
|
||||
<a href="mailto:me@example.com?cc=you@example.com%2Cthey@example.com" >me@example.com</a>
|
||||
<a href="mailto:me@example.com" class="email">me@example.com</a>
|
||||
<script type="text/javascript" language="javascript">
|
||||
<!--
|
||||
%27%29%3b'))</script>
|
||||
<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >me@domain.com</a>
|
||||
<a href="mailto:me@example.com?subject=Hello%20to%20you%21" >me@example.com</a>
|
||||
<a href="mailto:me@example.com?cc=you@example.com%2Cthey@example.com" >me@example.com</a>
|
||||
<a href="mailto:me@example.com" class="email">me@example.com</a>
|
||||
<script type="text/javascript" language="javascript">
|
||||
<!--
|
||||
{document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))}
|
||||
//-->
|
||||
</script></programlisting>
|
||||
//-->
|
||||
</script>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
Reference in New Issue
Block a user