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:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.foreach">
|
||||
<sect1 id="language.function.foreach">
|
||||
<title>foreach,foreachelse</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -70,49 +70,63 @@
|
||||
<emphasis>foreachelse</emphasis> is executed when there are no
|
||||
values in the <emphasis>from</emphasis> variable.
|
||||
</para>
|
||||
<example>
|
||||
<title>foreach</title>
|
||||
<programlisting>
|
||||
<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>
|
||||
{/foreach}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
id: 1000<br>
|
||||
id: 1001<br>
|
||||
id: 1002<br></programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>foreach key</title>
|
||||
<programlisting>
|
||||
{* 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")));
|
||||
|
||||
*}
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$contact}
|
||||
{$key}: {$item}<br>
|
||||
{* this example will print out all the values of the $custid array *}
|
||||
{foreach from=$custid item=curr_id}
|
||||
id: {$curr_id}<br />
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
id: 1000<br />
|
||||
id: 1001<br />
|
||||
id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
OUTPUT:
|
||||
<example>
|
||||
<title>foreach key</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* The key contains the key for each looped value
|
||||
|
||||
phone: 1<br>
|
||||
fax: 2<br>
|
||||
cell: 3<br>
|
||||
phone: 555-4444<br>
|
||||
fax: 555-3333<br>
|
||||
cell: 760-1234<br></programlisting>
|
||||
</example>
|
||||
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")));
|
||||
|
||||
*}
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$contact}
|
||||
{$key}: {$item}<br />
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
]]>
|
||||
</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>
|
||||
Foreach-loops also have their own variables that handle foreach properties.
|
||||
@@ -121,7 +135,6 @@ cell: 760-1234<br></programlisting>
|
||||
attribute of foreach
|
||||
</para>
|
||||
|
||||
|
||||
<sect2 id="foreach.property.iteration">
|
||||
<title>iteration</title>
|
||||
<para>
|
||||
@@ -166,29 +179,24 @@ 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:
|
||||
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
|
||||
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
|
||||
-->
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.if">
|
||||
<sect1 id="language.function.if">
|
||||
<title>if,elseif,else</title>
|
||||
<para>
|
||||
<emphasis>{if}</emphasis> statements in Smarty have much the same flexibility as PHP if
|
||||
@@ -136,89 +136,92 @@
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
<example>
|
||||
<title>if statements</title>
|
||||
<programlisting>
|
||||
{if $name eq "Fred"}
|
||||
<example>
|
||||
<title>if statements</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{if $name eq "Fred"}
|
||||
Welcome Sir.
|
||||
{elseif $name eq "Wilma"}
|
||||
{elseif $name eq "Wilma"}
|
||||
Welcome Ma'am.
|
||||
{else}
|
||||
{else}
|
||||
Welcome, whatever you are.
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* an example with "or" logic *}
|
||||
{if $name eq "Fred" or $name eq "Wilma"}
|
||||
{* an example with "or" logic *}
|
||||
{if $name eq "Fred" or $name eq "Wilma"}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* same as above *}
|
||||
{if $name == "Fred" || $name == "Wilma"}
|
||||
{* same as above *}
|
||||
{if $name == "Fred" || $name == "Wilma"}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* the following syntax will NOT work, conditional qualifiers
|
||||
{* the following syntax will NOT work, conditional qualifiers
|
||||
must be separated from surrounding elements by spaces *}
|
||||
{if $name=="Fred" || $name=="Wilma"}
|
||||
{if $name=="Fred" || $name=="Wilma"}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
|
||||
{* parenthesis are allowed *}
|
||||
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
|
||||
{* parenthesis are allowed *}
|
||||
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* you can also embed php function calls *}
|
||||
{if count($var) gt 0}
|
||||
{* you can also embed php function calls *}
|
||||
{if count($var) gt 0}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* test if values are even or odd *}
|
||||
{if $var is even}
|
||||
{* test if values are even or odd *}
|
||||
{if $var is even}
|
||||
...
|
||||
{/if}
|
||||
{if $var is odd}
|
||||
{/if}
|
||||
{if $var is odd}
|
||||
...
|
||||
{/if}
|
||||
{if $var is not odd}
|
||||
{/if}
|
||||
{if $var is not odd}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* test if var is divisible by 4 *}
|
||||
{if $var is div by 4}
|
||||
{* test if var is divisible by 4 *}
|
||||
{if $var is div by 4}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* test if var is even, grouped by two. i.e.,
|
||||
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
|
||||
{if $var is even by 2}
|
||||
{* test if var is even, grouped by two. i.e.,
|
||||
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
|
||||
{if $var is even by 2}
|
||||
...
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
|
||||
{if $var is even by 3}
|
||||
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
|
||||
{if $var is even by 3}
|
||||
...
|
||||
{/if}</programlisting>
|
||||
</example>
|
||||
{/if}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</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
|
||||
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
|
||||
-->
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.include.php">
|
||||
<sect1 id="language.function.include.php">
|
||||
<title>include_php</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -91,13 +91,14 @@
|
||||
The smarty object is available as $this within the PHP script that you
|
||||
include.
|
||||
</para>
|
||||
<example>
|
||||
<title>function include_php</title>
|
||||
<programlisting>
|
||||
load_nav.php
|
||||
-------------
|
||||
<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,37 +106,40 @@ load_nav.php
|
||||
$sql->query("select * from site_nav_sections order by name",SQL_ALL);
|
||||
$this->assign('sections',$sql->record);
|
||||
|
||||
?>
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.pl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* absolute path, or relative to $trusted_dir *}
|
||||
{include_php file="/path/to/load_nav.php"}
|
||||
|
||||
|
||||
index.tpl
|
||||
---------
|
||||
|
||||
{* 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>
|
||||
</example>
|
||||
{foreach item="curr_section" from=$sections}
|
||||
<a href="{$curr_section.url}">{$curr_section.name}</a><br />
|
||||
{/foreach}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</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
|
||||
-->
|
||||
<!-- 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.section">
|
||||
<sect1 id="language.function.section">
|
||||
<title>section,sectionelse</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -88,150 +88,178 @@
|
||||
[]. <emphasis>sectionelse</emphasis> is
|
||||
executed when there are no values in the loop variable.
|
||||
</para>
|
||||
<example>
|
||||
<title>section</title>
|
||||
<programlisting>
|
||||
<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 />
|
||||
{/section}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
id: 1000<br />
|
||||
id: 1001<br />
|
||||
id: 1002<br />
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
{* this example will print out all the values of the $custid array *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
id: 1000<br>
|
||||
id: 1001<br>
|
||||
id: 1002<br></programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>section loop variable</title>
|
||||
<programlisting>
|
||||
{* the loop variable only determines the number of times to loop.
|
||||
<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>
|
||||
{/section}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br />
|
||||
name: {$name[customer]}<br />
|
||||
address: {$address[customer]}<br />
|
||||
<p>
|
||||
{/section}
|
||||
]]>
|
||||
</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>
|
||||
|
||||
|
||||
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>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>section names</title>
|
||||
<programlisting>
|
||||
{* the name of the section can be anything you like,
|
||||
<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>
|
||||
</example>
|
||||
{section name=mydata loop=$custid}
|
||||
id: {$custid[mydata]}<br />
|
||||
name: {$name[mydata]}<br />
|
||||
address: {$address[mydata]}<br />
|
||||
<p>
|
||||
{/section}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>nested sections</title>
|
||||
<programlisting>
|
||||
{* sections can be nested as deep as you like. With nested sections,
|
||||
<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>
|
||||
{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>
|
||||
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br />
|
||||
{/section}
|
||||
<p>
|
||||
{/section}
|
||||
<p>
|
||||
{/section}
|
||||
]]>
|
||||
</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>
|
||||
|
||||
|
||||
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>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>sections and associative arrays</title>
|
||||
<programlisting>
|
||||
{* This is an example of printing an associative array
|
||||
<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>
|
||||
{/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}
|
||||
]]>
|
||||
</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>
|
||||
|
||||
|
||||
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>
|
||||
</example>
|
||||
|
||||
|
||||
|
||||
<example>
|
||||
<title>sectionelse</title>
|
||||
<programlisting>
|
||||
{* sectionelse will execute if there are no $custid values *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br>
|
||||
{sectionelse}
|
||||
<example>
|
||||
<title>sectionelse</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* sectionelse will execute if there are no $custid values *}
|
||||
{section name=customer loop=$custid}
|
||||
id: {$custid[customer]}<br />
|
||||
{sectionelse}
|
||||
there are no values in $custid.
|
||||
{/section}</programlisting>
|
||||
</example>
|
||||
{/section}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Sections also have their own variables that handle section properties.
|
||||
These are indicated like so: {$smarty.section.sectionname.varname}
|
||||
@@ -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>
|
||||
]]>
|
||||
</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>
|
||||
]]>
|
||||
</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>
|
||||
]]>
|
||||
</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:
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
current loop iteration: 1
|
||||
5 id: 1000<br>
|
||||
The customer id will change<br>
|
||||
5 id: 1000<br />
|
||||
The customer id will change<br />
|
||||
current loop iteration: 2
|
||||
7 id: 1001<br>
|
||||
The customer id will change<br>
|
||||
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>
|
||||
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>
|
||||
]]>
|
||||
</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>
|
||||
]]>
|
||||
</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>
|
||||
]]>
|
||||
</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>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.eval">
|
||||
<sect1 id="language.function.eval">
|
||||
<title>eval</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -63,39 +63,48 @@
|
||||
output will be cached with the rest of the template.
|
||||
</para>
|
||||
</note>
|
||||
<example>
|
||||
<title>eval</title>
|
||||
<programlisting>
|
||||
setup.conf
|
||||
----------
|
||||
<example>
|
||||
<title>eval</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
setup.conf
|
||||
----------
|
||||
|
||||
emphstart = <b>
|
||||
emphend = </b>
|
||||
title = Welcome to {$company}'s home page!
|
||||
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
|
||||
ErrorState = You must supply a {#emphstart#}state{#emphend#}.
|
||||
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#}.
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{config_load file="setup.conf"}
|
||||
|
||||
{eval var=$foo}
|
||||
{eval var=#title#}
|
||||
{eval var=#ErrorCity#}
|
||||
{eval var=#ErrorState# assign="state_error"}
|
||||
{$state_error}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
||||
index.tpl
|
||||
---------
|
||||
This is the contents of foo.
|
||||
Welcome to Foobar Pub & Grill's home page!
|
||||
You must supply a <strong>city</strong>.
|
||||
You must supply a <strong>state</strong>.
|
||||
|
||||
{config_load file="setup.conf"}
|
||||
|
||||
{eval var=$foo}
|
||||
{eval var=#title#}
|
||||
{eval var=#ErrorCity#}
|
||||
{eval var=#ErrorState# assign="state_error"}
|
||||
{$state_error}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
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>.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.html.image">
|
||||
<sect1 id="language.function.html.image">
|
||||
<title>html_image</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -98,12 +98,12 @@
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->display('index.tpl');
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
?>
|
||||
]]>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
where index.tpl is:
|
||||
|
@@ -70,86 +70,106 @@
|
||||
</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>
|
||||
<programlisting>
|
||||
EXAMPLE 1
|
||||
---------
|
||||
<example>
|
||||
<title>html_options : Example 1</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
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
|
||||
Johnson','Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
|
||||
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
|
||||
Johnson','Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
index.tpl:
|
||||
|
||||
<select name=customer_id>
|
||||
<select name=customer_id>
|
||||
{html_options values=$cust_ids selected=$customer_id output=$cust_names}
|
||||
</select>
|
||||
</select>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Example 2
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.php:
|
||||
----------
|
||||
|
||||
EXAMPLE 2
|
||||
---------
|
||||
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');
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Where index.tpl is:
|
||||
</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');
|
||||
|
||||
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>
|
||||
</example>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</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
|
||||
-->
|
||||
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
|
||||
-->
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.html.radios">
|
||||
<sect1 id="language.function.html.radios">
|
||||
<title>html_radios</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
@@ -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>
|
||||
<programlisting>
|
||||
index.php:
|
||||
<example>
|
||||
<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
|
||||
Johnson','Charlie Brown'));
|
||||
$smarty->assign('customer_id', 1001);
|
||||
$smarty->display('index.tpl');
|
||||
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
|
||||
Johnson','Charlie Brown'));
|
||||
$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:
|
||||
----------
|
||||
|
||||
|
||||
index.tpl:
|
||||
|
||||
{html_radios name="id" values=$cust_ids selected=$customer_id output=$cust_names separator="<br />"}
|
||||
|
||||
|
||||
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>
|
||||
</example>
|
||||
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');
|
||||
]]>
|
||||
</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,52 +105,58 @@
|
||||
<example>
|
||||
<title>mailto</title>
|
||||
<programlisting>
|
||||
{mailto address="me@example.com"}
|
||||
{mailto address="me@example.com" text="send me some mail"}
|
||||
{mailto address="me@example.com" encode="javascript"}
|
||||
{mailto address="me@example.com" encode="hex"}
|
||||
{mailto address="me@example.com" subject="Hello to you!"}
|
||||
{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
|
||||
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">
|
||||
<!--
|
||||
{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>
|
||||
</example>
|
||||
<![CDATA[
|
||||
{mailto address="me@example.com"}
|
||||
{mailto address="me@example.com" text="send me some mail"}
|
||||
{mailto address="me@example.com" encode="javascript"}
|
||||
{mailto address="me@example.com" encode="hex"}
|
||||
{mailto address="me@example.com" subject="Hello to you!"}
|
||||
{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"}
|
||||
]]>
|
||||
</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">
|
||||
<!--
|
||||
{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>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</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
|
||||
-->
|
||||
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
|
||||
-->
|
||||
|
Reference in New Issue
Block a user