Upgrade from Smarty 3 to Smarty 4 to be PHP 8.1 compatible

Remove all Smarty4 dedicated tests, all are done in the same test file
like before
This commit is contained in:
Clemens Schwaighofer
2022-04-06 15:12:50 +09:00
parent 4b0e9b44c3
commit f8ee6044f9
478 changed files with 33447 additions and 12496 deletions
@@ -0,0 +1,41 @@
{counter} {#language.function.counter}
=========
`{counter}` is used to print out a count. `{counter}` will remember the
count on each iteration. You can adjust the number, the interval and the
direction of the count, as well as determine whether or not to print the
value. You can run multiple counters concurrently by supplying a unique
name for each one. If you do not supply a name, the name "default" will
be used.
If you supply the `assign` attribute, the output of the `{counter}`
function will be assigned to this template variable instead of being
output to the template.
Attribute Name Type Required Default Description
---------------- --------- ---------- ----------- ------------------------------------------------------
name string No *default* The name of the counter
start number No *1* The initial number to start counting from
skip number No *1* The interval to count by
direction string No *up* The direction to count (up/down)
print boolean No *TRUE* Whether or not to print the value
assign string No *n/a* the template variable the output will be assigned to
{* initialize the count *}
{counter start=0 skip=2}<br />
{counter}<br />
{counter}<br />
{counter}<br />
this will output:
0<br />
2<br />
4<br />
6<br />
@@ -0,0 +1,57 @@
{cycle} {#language.function.cycle}
=======
`{cycle}` is used to alternate a set of values. This makes it easy to
for example, alternate between two or more colors in a table, or cycle
through an array of values.
Attribute Name Type Required Default Description
---------------- --------- ---------- ----------- -------------------------------------------------------------------------------------------------------------
name string No *default* The name of the cycle
values mixed Yes *N/A* The values to cycle through, either a comma delimited list (see delimiter attribute), or an array of values
print boolean No *TRUE* Whether to print the value or not
advance boolean No *TRUE* Whether or not to advance to the next value
delimiter string No *,* The delimiter to use in the values attribute
assign string No *n/a* The template variable the output will be assigned to
reset boolean No *FALSE* The cycle will be set to the first value and not advanced
- You can `{cycle}` through more than one set of values in a template
by supplying a `name` attribute. Give each `{cycle}` an unique
`name`.
- You can force the current value not to print with the `print`
attribute set to FALSE. This would be useful for silently skipping a
value.
- The `advance` attribute is used to repeat a value. When set to
FALSE, the next call to `{cycle}` will print the same value.
- If you supply the `assign` attribute, the output of the `{cycle}`
function will be assigned to a template variable instead of being
output to the template.
<!-- -->
{section name=rows loop=$data}
<tr class="{cycle values="odd,even"}">
<td>{$data[rows]}</td>
</tr>
{/section}
The above template would output:
<tr class="odd">
<td>1</td>
</tr>
<tr class="even">
<td>2</td>
</tr>
<tr class="odd">
<td>3</td>
</tr>
@@ -0,0 +1,15 @@
{debug} {#language.function.debug}
=======
`{debug}` dumps the debug console to the page. This works regardless of
the [debug](#chapter.debugging.console) settings in the php script.
Since this gets executed at runtime, this is only able to show the
[assigned](#api.assign) variables; not the templates that are in use.
However, you can see all the currently available variables within the
scope of a template.
Attribute Name Type Required Default Description
---------------- -------- ---------- -------------- ---------------------------------
output string No *javascript* output type, html or javascript
See also the [debugging console page](#chapter.debugging.console).
@@ -0,0 +1,84 @@
{eval} {#language.function.eval}
======
`{eval}` is used to evaluate a variable as a template. This can be used
for things like embedding template tags/variables into variables or
tags/variables into config file variables.
If you supply the `assign` attribute, the output of the `{eval}`
function will be assigned to this template variable instead of being
output to the template.
Attribute Name Type Required Default Description
---------------- -------- ---------- --------- ------------------------------------------------------
var mixed Yes *n/a* Variable (or string) to evaluate
assign string No *n/a* The template variable the output will be assigned to
> **Note**
>
> - Evaluated variables are treated the same as templates. They follow
> the same escapement and security features just as if they were
> templates.
>
> - Evaluated variables are compiled on every invocation, the compiled
> versions are not saved! However if you have [caching](#caching)
> enabled, the output will be cached with the rest of the template.
>
> - If the content to evaluate doesn\'t change often, or is used
> repeatedly, consider using
> `{include file="string:{$template_code}"}` instead. This may cache
> the compiled state and thus doesn\'t have to run the (comparably
> slow) compiler on every invocation.
>
The contents of the config file, `setup.conf`.
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#}.
Where the template is:
{config_load file='setup.conf'}
{eval var=$foo}
{eval var=#title#}
{eval var=#ErrorCity#}
{eval var=#ErrorState# assign='state_error'}
{$state_error}
The above template will output:
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>.
This outputs the server name (in uppercase) and IP. The assigned
variable `$str` could be from a database query.
<?php
$str = 'The server name is {$smarty.server.SERVER_NAME|upper} '
.'at {$smarty.server.SERVER_ADDR}';
$smarty->assign('foo',$str);
?>
Where the template is:
{eval var=$foo}
@@ -0,0 +1,59 @@
{fetch} {#language.function.fetch}
=======
`{fetch}` is used to retrieve files from the local file system, http, or
ftp and display the contents.
- If the file name begins with `http://`, the web site page will be
fetched and displayed.
> **Note**
>
> This will not support http redirects, be sure to include a
> trailing slash on your web page fetches where necessary.
- If the file name begins with `ftp://`, the file will be downloaded
from the ftp server and displayed.
- For local files, either a full system file path must be given, or a
path relative to the executed php script.
> **Note**
>
> If security is enabled and you are fetching a file from the local
> file system, `{fetch}` will only allow files from within the
> `$secure_dir` path of the securty policy. See the
> [Security](#advanced.features.security) section for details.
- If the `assign` attribute is set, the output of the `{fetch}`
function will be assigned to this template variable instead of being
output to the template.
Attribute Name Type Required Default Description
---------------- -------- ---------- --------- ------------------------------------------------------
file string Yes *n/a* The file, http or ftp site to fetch
assign string No *n/a* The template variable the output will be assigned to
{* include some javascript in your template *}
{fetch file='/export/httpd/www.example.com/docs/navbar.js'}
{* embed some weather text in your template from another web site *}
{fetch file='http://www.myweather.com/68502/'}
{* fetch a news headline file via ftp *}
{fetch file='ftp://user:password@ftp.example.com/path/to/currentheadlines.txt'}
{* as above but with variables *}
{fetch file="ftp://`$user`:`$password`@`$server`/`$path`"}
{* assign the fetched contents to a template variable *}
{fetch file='http://www.myweather.com/68502/' assign='weather'}
{if $weather ne ''}
<div id="weather">{$weather}</div>
{/if}
See also [`{capture}`](#language.function.capture),
[`{eval}`](#language.function.eval),
[`{assign}`](#language.function.assign) and [`fetch()`](#api.fetch).
@@ -0,0 +1,113 @@
{html\_checkboxes} {#language.function.html.checkboxes}
==================
`{html_checkboxes}` is a [custom function](#language.custom.functions)
that creates an html checkbox group with provided data. It takes care of
which item(s) are selected by default as well.
Attribute Name Type Required Default Description
---------------- ------------------- ------------------------------------- ------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name string No *checkbox* Name of checkbox list
values array Yes, unless using options attribute *n/a* An array of values for checkbox buttons
output array Yes, unless using options attribute *n/a* An array of output for checkbox buttons
selected string/array No *empty* The selected checkbox element(s)
options associative array Yes, unless using values and output *n/a* An associative array of values and output
separator string No *empty* String of text to separate each checkbox item
assign string No *empty* Assign checkbox tags to an array instead of output
labels boolean No *TRUE* Add \<label\>-tags to the output
label\_ids boolean No *FALSE* Add id-attributes to \<label\> and \<input\> to the output
escape boolean No *TRUE* Escape the output / content (values are always escaped)
strict boolean No *FALSE* Will make the \"extra\" attributes *disabled* and *readonly* only be set, if they were supplied with either boolean *TRUE* or string *\"disabled\"* and *\"readonly\"* respectively
- Required attributes are `values` and `output`, unless you use
`options` instead.
- All output is XHTML compliant.
- All parameters that are not in the list above are printed as
name/value-pairs inside each of the created \<input\>-tags.
<!-- -->
<?php
$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);
?>
where template is
{html_checkboxes name='id' values=$cust_ids output=$cust_names
selected=$customer_id separator='<br />'}
or where PHP code is:
<?php
$smarty->assign('cust_checkboxes', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown')
);
$smarty->assign('customer_id', 1001);
?>
and the template is
{html_checkboxes name='id' options=$cust_checkboxes
selected=$customer_id separator='<br />'}
both examples will output:
<label><input type="checkbox" name="id[]" value="1000" />Joe Schmoe</label><br />
<label><input type="checkbox" name="id[]" value="1001" checked="checked" />Jack Smith</label>
<br />
<label><input type="checkbox" name="id[]" value="1002" />Jane Johnson</label><br />
<label><input type="checkbox" name="id[]" value="1003" />Charlie Brown</label><br />
<?php
$sql = 'select type_id, types from contact_types order by type';
$smarty->assign('contact_types',$db->getAssoc($sql));
$sql = 'select contact_id, contact_type_id, contact '
.'from contacts where contact_id=12';
$smarty->assign('contact',$db->getRow($sql));
?>
The results of the database queries above would be output with.
{html_checkboxes name='contact_type_id' options=$contact_types
selected=$contact.contact_type_id separator='<br />'}
See also [`{html_radios}`](#language.function.html.radios) and
[`{html_options}`](#language.function.html.options)
@@ -0,0 +1,56 @@
{html\_image} {#language.function.html.image}
=============
`{html_image}` is a [custom function](#language.custom.functions) that
generates an HTML `<img>` tag. The `height` and `width` are
automatically calculated from the image file if they are not supplied.
Attribute Name Type Required Default Description
---------------- -------- ---------- ----------------------- ---------------------------------------
file string Yes *n/a* name/path to image
height string No *actual image height* Height to display image
width string No *actual image width* Width to display image
basedir string no *web server doc root* Directory to base relative paths from
alt string no *""* Alternative description of the image
href string no *n/a* href value to link the image to
path\_prefix string no *n/a* Prefix for output path
- `basedir` is the base directory that relative image paths are based
from. If not given, the web server\'s document root
`$_ENV['DOCUMENT_ROOT']` is used as the base. If security is
enabled, then the image must be located in the `$secure_dir` path of
the securty policy. See the [Security](#advanced.features.security)
section for details.
- `href` is the href value to link the image to. If link is supplied,
an `<a href="LINKVALUE"><a>` tag is placed around the image tag.
- `path_prefix` is an optional prefix string you can give the output
path. This is useful if you want to supply a different server name
for the image.
- All parameters that are not in the list above are printed as
name/value-pairs inside the created `<img>` tag.
> **Note**
>
> `{html_image}` requires a hit to the disk to read the image and
> calculate the height and width. If you don\'t use template
> [caching](#caching), it is generally better to avoid `{html_image}`
> and leave image tags static for optimal performance.
{html_image file='pumpkin.jpg'}
{html_image file='/path/from/docroot/pumpkin.jpg'}
{html_image file='../path/relative/to/currdir/pumpkin.jpg'}
Example output of the above template would be:
<img src="pumpkin.jpg" alt="" width="44" height="68" />
<img src="/path/from/docroot/pumpkin.jpg" alt="" width="44" height="68" />
<img src="../path/relative/to/currdir/pumpkin.jpg" alt="" width="44" height="68" />
@@ -0,0 +1,155 @@
{html\_options} {#language.function.html.options}
===============
`{html_options}` is a [custom function](#language.custom.functions) that
creates the html `<select><option>` group with the assigned data. It
takes care of which item(s) are selected by default as well.
Attribute Name Type Required Default Description
---------------- ------------------- ------------------------------------- --------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
values array Yes, unless using options attribute *n/a* An array of values for dropdown
output array Yes, unless using options attribute *n/a* An array of output for dropdown
selected string/array No *empty* The selected option element(s)
options associative array Yes, unless using values and output *n/a* An associative array of values and output
name string No *empty* Name of select group
strict boolean No *FALSE* Will make the \"extra\" attributes *disabled* and *readonly* only be set, if they were supplied with either boolean *TRUE* or string *\"disabled\"* and *\"readonly\"* respectively
- Required attributes are `values` and `output`, unless you use the
combined `options` instead.
- If the optional `name` attribute is given, the `<select></select>`
tags are created, otherwise ONLY the `<option>` list is generated.
- If a given value is an array, it will treat it as an html
`<optgroup>`, and display the groups. Recursion is supported with
`<optgroup>`.
- All parameters that are not in the list above are printed as
name/value-pairs inside the `<select>` tag. They are ignored if the
optional `name` is not given.
- All output is XHTML compliant.
<!-- -->
<?php
$smarty->assign('myOptions', array(
1800 => 'Joe Schmoe',
9904 => 'Jack Smith',
2003 => 'Charlie Brown')
);
$smarty->assign('mySelect', 9904);
?>
The following template will generate a drop-down list. Note the presence
of the `name` attribute which creates the `<select>` tags.
{html_options name=foo options=$myOptions selected=$mySelect}
Output of the above example would be:
<select name="foo">
<option value="1800">Joe Schmoe</option>
<option value="9904" selected="selected">Jack Smith</option>
<option value="2003">Charlie Brown</option>
</select>
<?php
$smarty->assign('cust_ids', array(56,92,13));
$smarty->assign('cust_names', array(
'Joe Schmoe',
'Jane Johnson',
'Charlie Brown'));
$smarty->assign('customer_id', 92);
?>
The above arrays would be output with the following template (note the
use of the php [`count()`](&url.php-manual;function.count) function as a
modifier to set the select size).
<select name="customer_id" size="{$cust_names|@count}">
{html_options values=$cust_ids output=$cust_names selected=$customer_id}
</select>
The above example would output:
<select name="customer_id" size="3">
<option value="56">Joe Schmoe</option>
<option value="92" selected="selected">Jane Johnson</option>
<option value="13">Charlie Brown</option>
</select>
<?php
$sql = 'select type_id, types from contact_types order by type';
$smarty->assign('contact_types',$db->getAssoc($sql));
$sql = 'select contact_id, name, email, contact_type_id
from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));
?>
Where a template could be as follows. Note the use of the
[`truncate`](#language.modifier.truncate) modifier.
<select name="type_id">
<option value='null'>-- none --</option>
{html_options options=$contact_types|truncate:20 selected=$contact.type_id}
</select>
<?php
$arr['Sport'] = array(6 => 'Golf', 9 => 'Cricket',7 => 'Swim');
$arr['Rest'] = array(3 => 'Sauna',1 => 'Massage');
$smarty->assign('lookups', $arr);
$smarty->assign('fav', 7);
?>
The script above and the following template
{html_options name=foo options=$lookups selected=$fav}
would output:
<select name="foo">
<optgroup label="Sport">
<option value="6">Golf</option>
<option value="9">Cricket</option>
<option value="7" selected="selected">Swim</option>
</optgroup>
<optgroup label="Rest">
<option value="3">Sauna</option>
<option value="1">Massage</option>
</optgroup>
</select>
See also [`{html_checkboxes}`](#language.function.html.checkboxes) and
[`{html_radios}`](#language.function.html.radios)
@@ -0,0 +1,112 @@
{html\_radios} {#language.function.html.radios}
==============
`{html_radios}` is a [custom function](#language.custom.functions) that
creates a HTML radio button group. It also takes care of which item is
selected by default as well.
Attribute Name Type Required Default Description
---------------- ------------------- ------------------------------------- --------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name string No *radio* Name of radio list
values array Yes, unless using options attribute *n/a* An array of values for radio buttons
output array Yes, unless using options attribute *n/a* An array of output for radio buttons
selected string No *empty* The selected radio element
options associative array Yes, unless using values and output *n/a* An associative array of values and output
separator string No *empty* String of text to separate each radio item
assign string No *empty* Assign radio tags to an array instead of output
labels boolean No *TRUE* Add \<label\>-tags to the output
label\_ids boolean No *FALSE* Add id-attributes to \<label\> and \<input\> to the output
escape boolean No *TRUE* Escape the output / content (values are always escaped)
strict boolean No *FALSE* Will make the \"extra\" attributes *disabled* and *readonly* only be set, if they were supplied with either boolean *TRUE* or string *\"disabled\"* and *\"readonly\"* respectively
- Required attributes are `values` and `output`, unless you use
`options` instead.
- All output is XHTML compliant.
- All parameters that are not in the list above are output as
name/value-pairs inside each of the created `<input>`-tags.
<!-- -->
<?php
$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);
?>
Where template is:
{html_radios name='id' values=$cust_ids output=$cust_names
selected=$customer_id separator='<br />'}
<?php
$smarty->assign('cust_radios', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown'));
$smarty->assign('customer_id', 1001);
?>
Where template is:
{html_radios name='id' options=$cust_radios
selected=$customer_id separator='<br />'}
Both examples will output:
<label><input type="radio" name="id" value="1000" />Joe Schmoe</label><br />
<label><input type="radio" name="id" value="1001" checked="checked" />Jack Smith</label><br />
<label><input type="radio" name="id" value="1002" />Jane Johnson</label><br />
<label><input type="radio" name="id" value="1003" />Charlie Brown</label><br />
<?php
$sql = 'select type_id, types from contact_types order by type';
$smarty->assign('contact_types',$db->getAssoc($sql));
$sql = 'select contact_id, name, email, contact_type_id '
.'from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));
?>
The variable assigned from the database above would be output with the
template:
{html_radios name='contact_type_id' options=$contact_types
selected=$contact.contact_type_id separator='<br />'}
See also [`{html_checkboxes}`](#language.function.html.checkboxes) and
[`{html_options}`](#language.function.html.options)
@@ -0,0 +1,119 @@
{html\_select\_date} {#language.function.html.select.date}
====================
`{html_select_date}` is a [custom function](#language.custom.functions)
that creates date dropdowns. It can display any or all of year, month,
and day. All parameters that are not in the list below are printed as
name/value-pairs inside the `<select>` tags of day, month and year.
Attribute Name Type Required Default Description
---------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
prefix string No Date\_ What to prefix the var name with
time [timestamp](&url.php-manual;function.time), [DateTime](&url.php-manual;class.DateTime), mysql timestamp or any string parsable by [`strtotime()`](&url.php-manual;strtotime), arrays as produced by this function if field\_array is set. No current [timestamp](&url.php-manual;function.time) What date/time to pre-select. If an array is given, the attributes field\_array and prefix are used to identify the array elements to extract year, month and day from. Omitting this parameter or supplying a falsy value will select the current date. To prevent date selection, pass in NULL
start\_year string No current year The first year in the dropdown, either year number, or relative to current year (+/- N)
end\_year string No same as start\_year The last year in the dropdown, either year number, or relative to current year (+/- N)
display\_days boolean No TRUE Whether to display days or not
display\_months boolean No TRUE Whether to display months or not
display\_years boolean No TRUE Whether to display years or not
month\_names array No null List of strings to display for months. array(1 =\> \'Jan\', ..., 12 =\> \'Dec\')
month\_format string No \%B What format the month should be in (strftime)
day\_format string No \%02d What format the day output should be in (sprintf)
day\_value\_format string No \%d What format the day value should be in (sprintf)
year\_as\_text boolean No FALSE Whether or not to display the year as text
reverse\_years boolean No FALSE Display years in reverse order
field\_array string No null If a name is given, the select boxes will be drawn such that the results will be returned to PHP in the form of name\[Day\], name\[Year\], name\[Month\].
day\_size string No null Adds size attribute to select tag if given
month\_size string No null Adds size attribute to select tag if given
year\_size string No null Adds size attribute to select tag if given
all\_extra string No null Adds extra attributes to all select/input tags if given
day\_extra string No null Adds extra attributes to select/input tags if given
month\_extra string No null Adds extra attributes to select/input tags if given
year\_extra string No null Adds extra attributes to select/input tags if given
all\_id string No null Adds id-attribute to all select/input tags if given
day\_id string No null Adds id-attribute to select/input tags if given
month\_id string No null Adds id-attribute to select/input tags if given
year\_id string No null Adds id-attribute to select/input tags if given
field\_order string No MDY The order in which to display the fields
field\_separator string No \\n String printed between different fields
month\_value\_format string No \%m strftime() format of the month values, default is %m for month numbers.
all\_empty string No null If supplied then the first element of any select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-boxes read "Please select" for example.
year\_empty string No null If supplied then the first element of the year\'s select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-box read "Please select a year" for example. Note that you can use values like "-MM-DD" as time-attribute to indicate an unselected year.
month\_empty string No null If supplied then the first element of the month\'s select-box has this value as it\'s label and "" as it\'s value. . Note that you can use values like "YYYY\--DD" as time-attribute to indicate an unselected month.
day\_empty string No null If supplied then the first element of the day\'s select-box has this value as it\'s label and "" as it\'s value. Note that you can use values like "YYYY-MM-" as time-attribute to indicate an unselected day.
> **Note**
>
> There is an useful php function on the [date tips page](#tips.dates)
> for converting `{html_select_date}` form values to a timestamp.
Template code
{html_select_date}
This will output:
<select name="Date_Month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
..... snipped .....
<option value="10">October</option>
<option value="11">November</option>
<option value="12" selected="selected">December</option>
</select>
<select name="Date_Day">
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
..... snipped .....
<option value="11">11</option>
<option value="12">12</option>
<option value="13" selected="selected">13</option>
<option value="14">14</option>
<option value="15">15</option>
..... snipped .....
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="Date_Year">
<option value="2006" selected="selected">2006</option>
</select>
{* start and end year can be relative to current year *}
{html_select_date prefix='StartDate' time=$time start_year='-5'
end_year='+1' display_days=false}
With 2000 as the current year the output:
<select name="StartDateMonth">
<option value="1">January</option>
<option value="2">February</option>
.... snipped ....
<option value="11">November</option>
<option value="12" selected="selected">December</option>
</select>
<select name="StartDateYear">
<option value="1995">1995</option>
.... snipped ....
<option value="1999">1999</option>
<option value="2000" selected="selected">2000</option>
<option value="2001">2001</option>
</select>
See also [`{html_select_time}`](#language.function.html.select.time),
[`date_format`](#language.modifier.date.format),
[`$smarty.now`](#language.variables.smarty.now) and the [date tips
page](#tips.dates).
@@ -0,0 +1,98 @@
{html\_select\_time} {#language.function.html.select.time}
====================
`{html_select_time}` is a [custom function](#language.custom.functions)
that creates time dropdowns for you. It can display any or all of hour,
minute, second and meridian.
The `time` attribute can have different formats. It can be a unique
timestamp, a string of the format `YYYYMMDDHHMMSS` or a string that is
parseable by PHP\'s [`strtotime()`](&url.php-manual;strtotime).
Attribute Name Type Required Default Description
----------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
prefix string No Time\_ What to prefix the var name with
time [timestamp](&url.php-manual;function.time), [DateTime](&url.php-manual;class.DateTime), mysql timestamp or any string parsable by [`strtotime()`](&url.php-manual;strtotime), arrays as produced by this function if field\_array is set. No current [timestamp](&url.php-manual;function.time) What date/time to pre-select. If an array is given, the attributes field\_array and prefix are used to identify the array elements to extract hour, minute, second and meridian from.
display\_hours boolean No TRUE Whether or not to display hours
display\_minutes boolean No TRUE Whether or not to display minutes
display\_seconds boolean No TRUE Whether or not to display seconds
display\_meridian boolean No TRUE Whether or not to display meridian (am/pm)
use\_24\_hours boolean No TRUE Whether or not to use 24 hour clock
minute\_interval integer No 1 Number interval in minute dropdown
second\_interval integer No 1 Number interval in second dropdown
hour\_format string No \%02d What format the hour label should be in (sprintf)
hour\_value\_format string No \%20d What format the hour value should be in (sprintf)
minute\_format string No \%02d What format the minute label should be in (sprintf)
minute\_value\_format string No \%20d What format the minute value should be in (sprintf)
second\_format string No \%02d What format the second label should be in (sprintf)
second\_value\_format string No \%20d What format the second value should be in (sprintf)
field\_array string No n/a Outputs values to array of this name
all\_extra string No null Adds extra attributes to select/input tags if given
hour\_extra string No null Adds extra attributes to select/input tags if given
minute\_extra string No null Adds extra attributes to select/input tags if given
second\_extra string No null Adds extra attributes to select/input tags if given
meridian\_extra string No null Adds extra attributes to select/input tags if given
field\_separator string No \\n String printed between different fields
option\_separator string No \\n String printed between different options of a field
all\_id string No null Adds id-attribute to all select/input tags if given
hour\_id string No null Adds id-attribute to select/input tags if given
minute\_id string No null Adds id-attribute to select/input tags if given
second\_id string No null Adds id-attribute to select/input tags if given
meridian\_id string No null Adds id-attribute to select/input tags if given
all\_empty string No null If supplied then the first element of any select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-boxes read "Please select" for example.
hour\_empty string No null If supplied then the first element of the hour\'s select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-box read "Please select an hour" for example.
minute\_empty string No null If supplied then the first element of the minute\'s select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-box read "Please select an minute" for example.
second\_empty string No null If supplied then the first element of the second\'s select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-box read "Please select an second" for example.
meridian\_empty string No null If supplied then the first element of the meridian\'s select-box has this value as it\'s label and "" as it\'s value. This is useful to make the select-box read "Please select an meridian" for example.
{html_select_time use_24_hours=true}
At 9:20 and 23 seconds in the morning the template above would output:
<select name="Time_Hour">
<option value="00">00</option>
<option value="01">01</option>
... snipped ....
<option value="08">08</option>
<option value="09" selected>09</option>
<option value="10">10</option>
... snipped ....
<option value="22">22</option>
<option value="23">23</option>
</select>
<select name="Time_Minute">
<option value="00">00</option>
<option value="01">01</option>
... snipped ....
<option value="19">19</option>
<option value="20" selected>20</option>
<option value="21">21</option>
... snipped ....
<option value="58">58</option>
<option value="59">59</option>
</select>
<select name="Time_Second">
<option value="00">00</option>
<option value="01">01</option>
... snipped ....
<option value="22">22</option>
<option value="23" selected>23</option>
<option value="24">24</option>
... snipped ....
<option value="58">58</option>
<option value="59">59</option>
</select>
<select name="Time_Meridian">
<option value="am" selected>AM</option>
<option value="pm">PM</option>
</select>
See also [`$smarty.now`](#language.variables.smarty.now),
[`{html_select_date}`](#language.function.html.select.date) and the
[date tips page](#tips.dates).
@@ -0,0 +1,89 @@
{html\_table} {#language.function.html.table}
=============
`{html_table}` is a [custom function](#language.custom.functions) that
dumps an array of data into an HTML `<table>`.
Attribute Name Type Required Default Description
---------------- --------- ---------- ---------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
loop array Yes *n/a* Array of data to loop through
cols mixed No *3* Number of columns in the table or a comma-separated list of column heading names or an array of column heading names.if the cols-attribute is empty, but rows are given, then the number of cols is computed by the number of rows and the number of elements to display to be just enough cols to display all elements. If both, rows and cols, are omitted cols defaults to 3. if given as a list or array, the number of columns is computed from the number of elements in the list or array.
rows integer No *empty* Number of rows in the table. if the rows-attribute is empty, but cols are given, then the number of rows is computed by the number of cols and the number of elements to display to be just enough rows to display all elements.
inner string No *cols* Direction of consecutive elements in the loop-array to be rendered. *cols* means elements are displayed col-by-col. *rows* means elements are displayed row-by-row.
caption string No *empty* Text to be used for the `<caption>` element of the table
table\_attr string No *border=\"1\"* Attributes for `<table>` tag
th\_attr string No *empty* Attributes for `<th>` tag (arrays are cycled)
tr\_attr string No *empty* attributes for `<tr>` tag (arrays are cycled)
td\_attr string No *empty* Attributes for `<td>` tag (arrays are cycled)
trailpad string No *&nbsp;* Value to pad the trailing cells on last row with (if any)
hdir string No *right* Direction of each row to be rendered. possible values: *right* (left-to-right), and *left* (right-to-left)
vdir string No *down* Direction of each column to be rendered. possible values: *down* (top-to-bottom), *up* (bottom-to-top)
- The `cols` attribute determines how many columns will be in the
table.
- The `table_attr`, `tr_attr` and `td_attr` values determine the
attributes given to the `<table>`, `<tr>` and `<td>` tags.
- If `tr_attr` or `td_attr` are arrays, they will be cycled through.
- `trailpad` is the value put into the trailing cells on the last
table row if there are any present.
<!-- -->
<?php
$smarty->assign( 'data', array(1,2,3,4,5,6,7,8,9) );
$smarty->assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') );
$smarty->display('index.tpl');
?>
The variables assigned from php could be displayed as these three
examples demonstrate. Each example shows the template followed by
output.
{**** Example One ****}
{html_table loop=$data}
<table border="1">
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</tbody>
</table>
{**** Example Two ****}
{html_table loop=$data cols=4 table_attr='border="0"'}
<table border="0">
<tbody>
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
{**** Example Three ****}
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
<table border="1">
<thead>
<tr>
<th>first</th><th>second</th><th>third</th><th>fourth</th>
</tr>
</thead>
<tbody>
<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
@@ -0,0 +1,56 @@
{mailto} {#language.function.mailto}
========
`{mailto}` automates the creation of a `mailto:` anchor links and
optionally encodes them. Encoding emails makes it more difficult for web
spiders to lift email addresses off of a site.
> **Note**
>
> Javascript is probably the most thorough form of encoding, although
> you can use hex encoding too.
Attribute Name Type Required Default Description
---------------- -------- ---------- --------- -----------------------------------------------------------------------------------------------
address string Yes *n/a* The e-mail address
text string No *n/a* The text to display, default is the e-mail address
encode string No *none* How to encode the e-mail. Can be one of `none`, `hex`, `javascript` or `javascript_charcode`.
cc string No *n/a* Email addresses to carbon copy, separate entries by a comma.
bcc string No *n/a* Email addresses to blind carbon copy, separate entries by a comma
subject string No *n/a* Email subject
newsgroups string No *n/a* Newsgroups to post to, separate entries by a comma.
followupto string No *n/a* Addresses to follow up to, separate entries by a comma.
extra string No *n/a* Any extra information you want passed to the link, such as style sheet classes
{mailto address="me@example.com"}
<a href="mailto:me@example.com" >me@example.com</a>
{mailto address="me@example.com" text="send me some mail"}
<a href="mailto:me@example.com" >send me some mail</a>
{mailto address="me@example.com" encode="javascript"}
<script type="text/javascript" language="javascript">
eval(unescape('%64%6f% ... snipped ...%61%3e%27%29%3b'))
</script>
{mailto address="me@example.com" encode="hex"}
<a href="mailto:%6d%65.. snipped..3%6f%6d">&#x6d;&..snipped...#x6f;&#x6d;</a>
{mailto address="me@example.com" subject="Hello to you!"}
<a href="mailto:me@example.com?subject=Hello%20to%20you%21" >me@example.com</a>
{mailto address="me@example.com" cc="you@example.com,they@example.com"}
<a href="mailto:me@example.com?cc=you@example.com,they@example.com" >me@example.com</a>
{mailto address="me@example.com" extra='class="email"'}
<a href="mailto:me@example.com" class="email">me@example.com</a>
{mailto address="me@example.com" encode="javascript_charcode"}
<script type="text/javascript" language="javascript">
{document.write(String.fromCharCode(60,97, ... snipped ....60,47,97,62))}
</script>
See also [`escape`](#language.modifier.escape),
[`{textformat}`](#language.function.textformat) and [obfuscating email
addresses](#tips.obfuscating.email).
@@ -0,0 +1,104 @@
{math} {#language.function.math}
======
`{math}` allows the template designer to do math equations in the
template.
- Any numeric template variables may be used in the equations, and the
result is printed in place of the tag.
- The variables used in the equation are passed as parameters, which
can be template variables or static values.
- +, -, /, \*, abs, ceil, cos, exp, floor, log, log10, max, min, pi,
pow, rand, round, sin, sqrt, srans and tan are all valid operators.
Check the PHP documentation for further information on these
[math](&url.php-manual;eval) functions.
- If you supply the `assign` attribute, the output of the `{math}`
function will be assigned to this template variable instead of being
output to the template.
> **Note**
>
> `{math}` is an expensive function in performance due to its use of the
> php [`eval()`](&url.php-manual;eval) function. Doing the math in PHP
> is much more efficient, so whenever possible do the math calculations
> in the script and [`assign()`](#api.assign) the results to the
> template. Definitely avoid repetitive `{math}` function calls, eg
> within [`{section}`](#language.function.section) loops.
Attribute Name Type Required Default Description
---------------- --------- ---------- --------- --------------------------------------------------
equation string Yes *n/a* The equation to execute
format string No *n/a* The format of the result (sprintf)
var numeric Yes *n/a* Equation variable value
assign string No *n/a* Template variable the output will be assigned to
\[var \...\] numeric Yes *n/a* Equation variable value
**Example a:**
{* $height=4, $width=5 *}
{math equation="x + y" x=$height y=$width}
The above example will output:
9
**Example b:**
{* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *}
{math equation="height * width / division"
height=$row_height
width=$row_width
division=#col_div#}
The above example will output:
100
**Example c:**
{* you can use parenthesis *}
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
The above example will output:
6
**Example d:**
{* you can supply a format parameter in sprintf format *}
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
The above example will output:
9.44
@@ -0,0 +1,190 @@
{textformat} {#language.function.textformat}
============
`{textformat}` is a [block function](#plugins.block.functions) used to
format text. It basically cleans up spaces and special characters, and
formats paragraphs by wrapping at a boundary and indenting lines.
You can set the parameters explicitly, or use a preset style. Currently
"email" is the only available style.
Attribute Name Type Required Default Description
---------------- --------- ---------- ------------------ ----------------------------------------------------------------------------------------
style string No *n/a* Preset style
indent number No *0* The number of chars to indent every line
indent\_first number No *0* The number of chars to indent the first line
indent\_char string No *(single space)* The character (or string of chars) to indent with
wrap number No *80* How many characters to wrap each line to
wrap\_char string No *\\n* The character (or string of chars) to break each line with
wrap\_cut boolean No *FALSE* If TRUE, wrap will break the line at the exact character instead of at a word boundary
assign string No *n/a* The template variable the output will be assigned to
{textformat wrap=40}
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is bar.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
{/textformat}
The above example will output:
This is foo. This is foo. This is foo.
This is foo. This is foo. This is foo.
This is bar.
bar foo bar foo foo. bar foo bar foo
foo. bar foo bar foo foo. bar foo bar
foo foo. bar foo bar foo foo. bar foo
bar foo foo. bar foo bar foo foo.
{textformat wrap=40 indent=4}
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is bar.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
{/textformat}
The above example will output:
This is foo. This is foo. This is
foo. This is foo. This is foo. This
is foo.
This is bar.
bar foo bar foo foo. bar foo bar foo
foo. bar foo bar foo foo. bar foo
bar foo foo. bar foo bar foo foo.
bar foo bar foo foo. bar foo bar
foo foo.
{textformat wrap=40 indent=4 indent_first=4}
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is bar.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
{/textformat}
The above example will output:
This is foo. This is foo. This
is foo. This is foo. This is foo.
This is foo.
This is bar.
bar foo bar foo foo. bar foo bar
foo foo. bar foo bar foo foo. bar
foo bar foo foo. bar foo bar foo
foo. bar foo bar foo foo. bar foo
bar foo foo.
{textformat style="email"}
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is foo.
This is bar.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
bar foo bar foo foo.
{/textformat}
The above example will output:
This is foo. This is foo. This is foo. This is foo. This is foo. This is
foo.
This is bar.
bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo
bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo
foo.
See also [`{strip}`](#language.function.strip) and
[`wordwrap`](#language.modifier.wordwrap).