mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-16 05:55:20 +02:00
Finished improving designers docs
This commit is contained in:
19
docs/designers/language-custom-functions/index.md
Normal file
19
docs/designers/language-custom-functions/index.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Custom Functions
|
||||
|
||||
Smarty comes with several custom plugin functions that you can use in
|
||||
the templates.
|
||||
|
||||
- [{counter}](language-function-counter.md)
|
||||
- [{cycle}](language-function-cycle.md)
|
||||
- [{eval}](language-function-eval.md)
|
||||
- [{fetch}](language-function-fetch.md)
|
||||
- [{html_checkboxes}](language-function-html-checkboxes.md)
|
||||
- [{html_image}](language-function-html-image.md)
|
||||
- [{html_options}](language-function-html-options.md)
|
||||
- [{html_radios}](language-function-html-radios.md)
|
||||
- [{html_select_date}](language-function-html-select-date.md)
|
||||
- [{html_select_time}](language-function-html-select-time.md)
|
||||
- [{html_table}](language-function-html-table.md)
|
||||
- [{mailto}](language-function-mailto.md)
|
||||
- [{math}](language-function-math.md)
|
||||
- [{textformat}](language-function-textformat.md)
|
@@ -1,41 +1,45 @@
|
||||
{counter} {#language.function.counter}
|
||||
=========
|
||||
# {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
|
||||
direction of the count, as well as determine whether 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.
|
||||
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|-----------------------------------------------------------|
|
||||
| name | No | The name of the counter |
|
||||
| start | No | The initial number to start counting from (defaults to 1) |
|
||||
| skip | No | The interval to count by (defaults to 1) |
|
||||
| direction | No | The direction to count (up/down) (defaults to 'up') |
|
||||
| print | No | Whether or not to print the value (defaults to true) |
|
||||
| assign | No | the template variable the output will be assigned to |
|
||||
|
||||
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
|
||||
## Examples
|
||||
|
||||
```smarty
|
||||
|
||||
{* initialize the count *}
|
||||
{counter start=0 skip=2}<br />
|
||||
{counter}<br />
|
||||
{counter}<br />
|
||||
{counter}<br />
|
||||
{* 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 />
|
||||
|
||||
```html
|
||||
0<br />
|
||||
2<br />
|
||||
4<br />
|
||||
6<br />
|
||||
```
|
||||
|
||||
|
@@ -1,22 +1,23 @@
|
||||
{cycle} {#language.function.cycle}
|
||||
=======
|
||||
# {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
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|-------------------------------------------------------------------------------------------------------------|
|
||||
| name | No | The name of the cycle |
|
||||
| values | Yes | The values to cycle through, either a comma delimited list (see delimiter attribute), or an array of values |
|
||||
| print | No | Whether to print the value or not (defaults to true) |
|
||||
| advance | No | Whether or not to advance to the next value (defaults to true) |
|
||||
| delimiter | No | The delimiter to use in the values attribute (defaults to ',') |
|
||||
| assign | No | The template variable the output will be assigned to |
|
||||
| reset | No | The cycle will be set to the first value and not advanced (defaults to false) |
|
||||
|
||||
- You can `{cycle}` through more than one set of values in a template
|
||||
by supplying a `name` attribute. Give each `{cycle}` an unique
|
||||
by supplying a `name` attribute. Give each `{cycle}` a unique
|
||||
`name`.
|
||||
|
||||
- You can force the current value not to print with the `print`
|
||||
@@ -30,20 +31,18 @@ through an array of values.
|
||||
function will be assigned to a template variable instead of being
|
||||
output to the template.
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
{section name=rows loop=$data}
|
||||
## Examples
|
||||
```smarty
|
||||
{section name=rows loop=$data}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$data[rows]}</td>
|
||||
</tr>
|
||||
{/section}
|
||||
|
||||
|
||||
{/section}
|
||||
```
|
||||
|
||||
The above template would output:
|
||||
|
||||
|
||||
```html
|
||||
<tr class="odd">
|
||||
<td>1</td>
|
||||
</tr>
|
||||
@@ -53,5 +52,4 @@ The above template would output:
|
||||
<tr class="odd">
|
||||
<td>3</td>
|
||||
</tr>
|
||||
|
||||
|
||||
```
|
||||
|
@@ -1,15 +1,14 @@
|
||||
{debug} {#language.function.debug}
|
||||
=======
|
||||
# {debug}
|
||||
|
||||
`{debug}` dumps the debug console to the page. This works regardless of
|
||||
the [debug](#chapter.debugging.console) settings in the php script.
|
||||
the [debug](../chapter-debugging-console.md) 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.
|
||||
[assigned](../../programmers/api-functions/api-assign.md) 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
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|------------------------------------------------------------|
|
||||
| output | No | output type, html or javascript (defaults to 'javascript') |
|
||||
|
||||
See also the [debugging console page](#chapter.debugging.console).
|
||||
See also the [debugging console page](../chapter-debugging-console.md).
|
||||
|
@@ -1,19 +1,20 @@
|
||||
{eval} {#language.function.eval}
|
||||
======
|
||||
# {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.
|
||||
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|------------------------------------------------------|
|
||||
| var | Yes | Variable (or string) to evaluate |
|
||||
| assign | No | The template variable the output will be assigned to |
|
||||
|
||||
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
|
||||
@@ -21,64 +22,60 @@ output to the template.
|
||||
> templates.
|
||||
>
|
||||
> - Evaluated variables are compiled on every invocation, the compiled
|
||||
> versions are not saved! However if you have [caching](#caching)
|
||||
> versions are not saved! However, if you have [caching](../../programmers/caching.md)
|
||||
> enabled, the output will be cached with the rest of the template.
|
||||
>
|
||||
> - If the content to evaluate doesn\'t change often, or is used
|
||||
> - 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
|
||||
> the compiled state and thus doesn't have to run the (comparably
|
||||
> slow) compiler on every invocation.
|
||||
>
|
||||
|
||||
## Examples
|
||||
|
||||
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#}.
|
||||
|
||||
|
||||
```ini
|
||||
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:
|
||||
|
||||
```smarty
|
||||
{config_load file='setup.conf'}
|
||||
|
||||
{config_load file='setup.conf'}
|
||||
|
||||
{eval var=$foo}
|
||||
{eval var=#title#}
|
||||
{eval var=#ErrorCity#}
|
||||
{eval var=#ErrorState# assign='state_error'}
|
||||
{$state_error}
|
||||
|
||||
{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>.
|
||||
|
||||
|
||||
```html
|
||||
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
|
||||
```php
|
||||
<?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}
|
||||
|
||||
|
||||
```smarty
|
||||
{eval var=$foo}
|
||||
```
|
||||
|
@@ -1,10 +1,15 @@
|
||||
{fetch} {#language.function.fetch}
|
||||
=======
|
||||
# {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
|
||||
## Attributes
|
||||
| Attribute | Required | Description |
|
||||
|-----------|----------|------------------------------------------------------|
|
||||
| file | Yes | The file, http or ftp site to fetch |
|
||||
| assign | No | The template variable the output will be assigned to |
|
||||
|
||||
- If the file name begins with `http://`, the website page will be
|
||||
fetched and displayed.
|
||||
|
||||
> **Note**
|
||||
@@ -20,40 +25,37 @@ ftp and display the contents.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If security is enabled and you are fetching a file from the local
|
||||
> 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 security policy. See the
|
||||
> [Security](#advanced.features.security) section for details.
|
||||
> [Security](../../programmers/advanced-features/advanced-features-security.md) 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
|
||||
## Examples
|
||||
|
||||
```smarty
|
||||
{* include some javascript in your template *}
|
||||
{fetch file='/export/httpd/www.example.com/docs/navbar.js'}
|
||||
|
||||
{* 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/'}
|
||||
|
||||
{* 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}
|
||||
{* 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).
|
||||
See also [`{capture}`](../language-builtin-functions/language-function-capture.md),
|
||||
[`{eval}`](language-function-eval.md),
|
||||
[`{assign}`](../language-builtin-functions/language-function-assign.md) and [`fetch()`](../../programmers/api-functions/api-fetch.md).
|
||||
|
@@ -1,113 +1,102 @@
|
||||
{html\_checkboxes} {#language.function.html.checkboxes}
|
||||
==================
|
||||
# {html_checkboxes}
|
||||
|
||||
`{html_checkboxes}` is a [custom function](#language.custom.functions)
|
||||
`{html_checkboxes}` is a [custom function](index.md)
|
||||
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
|
||||
## Attributes
|
||||
|
||||
- Required attributes are `values` and `output`, unless you use
|
||||
`options` instead.
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| name | No | Name of checkbox list (defaults to 'checkbox') |
|
||||
| values | Yes, unless using options attribute | An array of values for checkbox buttons |
|
||||
| output | Yes, unless using options attribute | An array of output for checkbox buttons |
|
||||
| selected | No | The selected checkbox element(s) as a string or array |
|
||||
| options | Yes, unless using values and output | An associative array of values and output |
|
||||
| separator | No | String of text to separate each checkbox item |
|
||||
| assign | No | Assign checkbox tags to an array instead of output |
|
||||
| labels | No | Add <label\>-tags to the output (defaults to true) |
|
||||
| label\_ids | No | Add id-attributes to <label\> and <input\> to the output (defaults to false) |
|
||||
| escape | No | Escape the output / content (values are always escaped) (defaults to true) |
|
||||
| strict | No | 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 (defaults to false) |
|
||||
|
||||
- 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.
|
||||
name/value-pairs inside each of the created <input\>-tags.
|
||||
|
||||
<!-- -->
|
||||
## Examples
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
<?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);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
$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 />'}
|
||||
|
||||
|
||||
```smarty
|
||||
{html_checkboxes name='id' values=$cust_ids output=$cust_names selected=$customer_id separator='<br />'}
|
||||
```
|
||||
|
||||
or where PHP code is:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('cust_checkboxes', array(
|
||||
1000 => 'Joe Schmoe',
|
||||
1001 => 'Jack Smith',
|
||||
1002 => 'Jane Johnson',
|
||||
1003 => 'Charlie Brown')
|
||||
);
|
||||
$smarty->assign('customer_id', 1001);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
$smarty->assign(
|
||||
'cust_checkboxes',
|
||||
[
|
||||
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 />'}
|
||||
|
||||
|
||||
```smarty
|
||||
{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 />
|
||||
|
||||
```html
|
||||
<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
|
||||
<?php
|
||||
|
||||
<?php
|
||||
$sql = 'select type_id, types from contact_types order by type';
|
||||
$smarty->assign('contact_types',$db->getAssoc($sql));
|
||||
|
||||
$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));
|
||||
|
||||
?>
|
||||
|
||||
|
||||
$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.
|
||||
|
||||
```smarty
|
||||
{html_checkboxes name='contact_type_id' options=$contact_types selected=$contact.contact_type_id separator='<br />'}
|
||||
```
|
||||
|
||||
{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)
|
||||
See also [`{html_radios}`](./language-function-html-radios.md) and
|
||||
[`{html_options}`](./language-function-html-options.md)
|
||||
|
@@ -1,25 +1,26 @@
|
||||
{html\_image} {#language.function.html.image}
|
||||
=============
|
||||
# {html_image}
|
||||
|
||||
`{html_image}` is a [custom function](#language.custom.functions) that
|
||||
`{html_image}` is a [custom function](index.md) 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
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|-------------------------------------------------------------------------|
|
||||
| file | Yes | name/path to image |
|
||||
| height | No | Height to display image (defaults to actual image height) |
|
||||
| width | No | Width to display image (defaults to actual image width) |
|
||||
| basedir | no | Directory to base relative paths from (defaults to web server doc root) |
|
||||
| alt | no | Alternative description of the image |
|
||||
| href | no | href value to link the image to |
|
||||
| path\_prefix | no | 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
|
||||
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 security policy. See the [Security](#advanced.features.security)
|
||||
the security policy. See the [Security](../../programmers/advanced-features/advanced-features-security.md)
|
||||
section for details.
|
||||
|
||||
- `href` is the href value to link the image to. If link is supplied,
|
||||
@@ -35,22 +36,23 @@ automatically calculated from the image file if they are not supplied.
|
||||
> **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}`
|
||||
> calculate the height and width. If you don't use template
|
||||
> [caching](../../programmers/caching.md), it is generally better to avoid `{html_image}`
|
||||
> and leave image tags static for optimal performance.
|
||||
|
||||
## Examples
|
||||
|
||||
{html_image file='pumpkin.jpg'}
|
||||
{html_image file='/path/from/docroot/pumpkin.jpg'}
|
||||
{html_image file='../path/relative/to/currdir/pumpkin.jpg'}
|
||||
|
||||
|
||||
```smarty
|
||||
{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" />
|
||||
|
||||
```html
|
||||
<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" />
|
||||
```
|
||||
|
||||
|
@@ -1,18 +1,19 @@
|
||||
{html\_options} {#language.function.html.options}
|
||||
===============
|
||||
# {html_options}
|
||||
|
||||
`{html_options}` is a [custom function](#language.custom.functions) that
|
||||
`{html_options}` is a [custom function](index.md) 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
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| values | Yes, unless using options attribute | An array of values for dropdown |
|
||||
| output | Yes, unless using options attribute | An array of output for dropdown |
|
||||
| selected | No | The selected option element(s) as a string or array |
|
||||
| options | Yes, unless using values and output | An associative array of values and output |
|
||||
| name | No | Name of select group |
|
||||
| strict | No | 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 (defaults to false) |
|
||||
|
||||
- Required attributes are `values` and `output`, unless you use the
|
||||
combined `options` instead.
|
||||
@@ -30,126 +31,116 @@ takes care of which item(s) are selected by default as well.
|
||||
|
||||
- All output is XHTML compliant.
|
||||
|
||||
<!-- -->
|
||||
## Examples
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->assign('myOptions', array(
|
||||
1800 => 'Joe Schmoe',
|
||||
9904 => 'Jack Smith',
|
||||
2003 => 'Charlie Brown')
|
||||
);
|
||||
$smarty->assign('mySelect', 9904);
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('myOptions', [
|
||||
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}
|
||||
|
||||
|
||||
```smarty
|
||||
{html_options name=foo options=$myOptions selected=$mySelect}
|
||||
```
|
||||
|
||||
Output of the above example would be:
|
||||
|
||||
|
||||
<select name="foo">
|
||||
```html
|
||||
<select name="foo">
|
||||
<option value="1800">Joe Schmoe</option>
|
||||
<option value="9904" selected="selected">Jack Smith</option>
|
||||
<option value="2003">Charlie Brown</option>
|
||||
</select>
|
||||
</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);
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('cust_ids', [56,92,13]);
|
||||
$smarty->assign('cust_names', [
|
||||
'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()`](https://www.php.net/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>
|
||||
|
||||
|
||||
```smarty
|
||||
<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:
|
||||
|
||||
```html
|
||||
<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>
|
||||
```
|
||||
|
||||
<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
|
||||
<?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));
|
||||
|
||||
|
||||
<?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.
|
||||
[`truncate`](../language-modifiers/language-modifier-truncate.md) modifier.
|
||||
|
||||
```smarty
|
||||
<select name="type_id">
|
||||
<option value='null'>-- none --</option>
|
||||
{html_options options=$contact_types|truncate:20 selected=$contact.type_id}
|
||||
</select>
|
||||
```
|
||||
|
||||
<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);
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?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}
|
||||
|
||||
|
||||
```smarty
|
||||
{html_options name=foo options=$lookups selected=$fav}
|
||||
```
|
||||
|
||||
would output:
|
||||
|
||||
|
||||
<select name="foo">
|
||||
```html
|
||||
<select name="foo">
|
||||
<optgroup label="Sport">
|
||||
<option value="6">Golf</option>
|
||||
<option value="9">Cricket</option>
|
||||
<option value="7" selected="selected">Swim</option>
|
||||
<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>
|
||||
<option value="3">Sauna</option>
|
||||
<option value="1">Massage</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</select>
|
||||
```
|
||||
|
||||
See also [`{html_checkboxes}`](#language.function.html.checkboxes) and
|
||||
[`{html_radios}`](#language.function.html.radios)
|
||||
See also [`{html_checkboxes}`](./language-function-html-checkboxes.md) and
|
||||
[`{html_radios}`](./language-function-html-radios.md)
|
||||
|
@@ -1,23 +1,24 @@
|
||||
{html\_radios} {#language.function.html.radios}
|
||||
==============
|
||||
# {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
|
||||
`{html_radios}` is a [custom function](index.md) that
|
||||
creates an 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
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| name | No | Name of radio list |
|
||||
| values | Yes, unless using options attribute | An array of values for radio buttons |
|
||||
| output | Yes, unless using options attribute | An array of output for radio buttons |
|
||||
| selected | No | The selected radio element |
|
||||
| options | Yes, unless using values and output | An associative array of values and output |
|
||||
| separator | No | String of text to separate each radio item |
|
||||
| assign | No | Assign radio tags to an array instead of output |
|
||||
| labels | No | Add <label>-tags to the output (defaults to true) |
|
||||
| label\_ids | No | Add id-attributes to <label\> and <input\> to the output (defaults to false) |
|
||||
| escape | No | Escape the output / content (values are always escaped) (defaults to true) |
|
||||
| strict | No | 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 (defaults to false) |
|
||||
|
||||
- Required attributes are `values` and `output`, unless you use
|
||||
`options` instead.
|
||||
@@ -27,86 +28,77 @@ selected by default as well.
|
||||
- All parameters that are not in the list above are output as
|
||||
name/value-pairs inside each of the created `<input>`-tags.
|
||||
|
||||
<!-- -->
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
<?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);
|
||||
|
||||
?>
|
||||
|
||||
$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:
|
||||
|
||||
```smarty
|
||||
{html_radios name='id' values=$cust_ids output=$cust_names
|
||||
selected=$customer_id separator='<br />'}
|
||||
```
|
||||
|
||||
|
||||
```php
|
||||
<?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:
|
||||
|
||||
```smarty
|
||||
|
||||
{html_radios name='id' values=$cust_ids output=$cust_names
|
||||
selected=$customer_id separator='<br />'}
|
||||
|
||||
{html_radios name='id' options=$cust_radios
|
||||
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 />
|
||||
|
||||
```html
|
||||
<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
|
||||
|
||||
<?php
|
||||
|
||||
<?php
|
||||
$sql = 'select type_id, types from contact_types order by type';
|
||||
$smarty->assign('contact_types',$db->getAssoc($sql));
|
||||
|
||||
$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));
|
||||
|
||||
$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:
|
||||
|
||||
```smarty
|
||||
{html_radios name='contact_type_id' options=$contact_types
|
||||
selected=$contact.contact_type_id separator='<br />'}
|
||||
```
|
||||
|
||||
{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)
|
||||
See also [`{html_checkboxes}`](language-function-html-checkboxes.md) and
|
||||
[`{html_options}`](language-function-html-options.md)
|
||||
|
@@ -1,62 +1,64 @@
|
||||
{html\_select\_date} {#language.function.html.select.date}
|
||||
====================
|
||||
# {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,
|
||||
`{html_select_date}` is a [custom function](index.md)
|
||||
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](https://www.php.net/function.time), [DateTime](https://www.php.net/class.DateTime), mysql timestamp or any string parsable by [`strtotime()`](https://www.php.net/strtotime), arrays as produced by this function if field\_array is set. No current [timestamp](https://www.php.net/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.
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Default | Description |
|
||||
|--------------------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| prefix | Date_ | What to prefix the var name with |
|
||||
| time | | What date/time to pre-select. Accepts timestamps, DateTime objects or any string parseable by [strtotime()](https://www.php.net/strtotime). 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 | current year | The first year in the dropdown, either year number, or relative to current year (+/- N) |
|
||||
| end_year | same as start_year | The last year in the dropdown, either year number, or relative to current year (+/- N) |
|
||||
| display_days | TRUE | Whether to display days or not |
|
||||
| display_months | TRUE | Whether to display months or not |
|
||||
| display_years | TRUE | Whether to display years or not |
|
||||
| month_names | | List of strings to display for months. array(1 =\> 'Jan', ..., 12 =\> 'Dec') |
|
||||
| month_format | \%B | What format the month should be in (strftime) |
|
||||
| day_format | \%02d | What format the day output should be in (sprintf) |
|
||||
| day_value_format | \%d | What format the day value should be in (sprintf) |
|
||||
| year_as_text | FALSE | Whether or not to display the year as text |
|
||||
| reverse_years | FALSE | Display years in reverse order |
|
||||
| field_array | | 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 | | Adds size attribute to select tag if given |
|
||||
| month_size | | Adds size attribute to select tag if given |
|
||||
| year_size | | Adds size attribute to select tag if given |
|
||||
| all_extra | | Adds extra attributes to all select/input tags if given |
|
||||
| day_extra | | Adds extra attributes to select/input tags if given |
|
||||
| month_extra | | Adds extra attributes to select/input tags if given |
|
||||
| year_extra | | Adds extra attributes to select/input tags if given |
|
||||
| all_id | | Adds id-attribute to all select/input tags if given |
|
||||
| day_id | | Adds id-attribute to select/input tags if given |
|
||||
| month_id | | Adds id-attribute to select/input tags if given |
|
||||
| year_id | | Adds id-attribute to select/input tags if given |
|
||||
| field_order | MDY | The order in which to display the fields |
|
||||
| field_separator | \\n | String printed between different fields |
|
||||
| month_value_format | \%m | strftime() format of the month values, default is %m for month numbers. |
|
||||
| all_empty | | 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 | | 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 | | 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 | | 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)
|
||||
> There is an useful php function on the [date tips page](../../appendixes/tips.md)
|
||||
> for converting `{html_select_date}` form values to a timestamp.
|
||||
|
||||
## Exaples
|
||||
|
||||
Template code
|
||||
|
||||
|
||||
{html_select_date}
|
||||
|
||||
|
||||
```smarty
|
||||
{html_select_date}
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
|
||||
<select name="Date_Month">
|
||||
```html
|
||||
<select name="Date_Month">
|
||||
<option value="1">January</option>
|
||||
<option value="2">February</option>
|
||||
<option value="3">March</option>
|
||||
@@ -64,8 +66,8 @@ This will output:
|
||||
<option value="10">October</option>
|
||||
<option value="11">November</option>
|
||||
<option value="12" selected="selected">December</option>
|
||||
</select>
|
||||
<select name="Date_Day">
|
||||
</select>
|
||||
<select name="Date_Day">
|
||||
<option value="1">01</option>
|
||||
<option value="2">02</option>
|
||||
<option value="3">03</option>
|
||||
@@ -79,41 +81,38 @@ This will output:
|
||||
<option value="29">29</option>
|
||||
<option value="30">30</option>
|
||||
<option value="31">31</option>
|
||||
</select>
|
||||
<select name="Date_Year">
|
||||
</select>
|
||||
<select name="Date_Year">
|
||||
<option value="2006" selected="selected">2006</option>
|
||||
</select>
|
||||
|
||||
</select>
|
||||
```
|
||||
|
||||
|
||||
|
||||
{* start and end year can be relative to current year *}
|
||||
{html_select_date prefix='StartDate' time=$time start_year='-5'
|
||||
```smarty
|
||||
{* 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">
|
||||
```html
|
||||
<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">
|
||||
</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>
|
||||
|
||||
</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).
|
||||
See also [`{html_select_time}`](language-function-html-select-time.md),
|
||||
[`date_format`](../language-modifiers/language-modifier-date-format.md),
|
||||
[`$smarty.now`](../language-variables/language-variables-smarty.md#smartynow-languagevariablessmartynow) and the [date tips
|
||||
page](../../appendixes/tips.md#dates).
|
||||
|
@@ -1,59 +1,62 @@
|
||||
{html\_select\_time} {#language.function.html.select.time}
|
||||
====================
|
||||
# {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,
|
||||
`{html_select_time}` is a [custom function](index.md)
|
||||
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()`](https://www.php.net/strtotime).
|
||||
parseable by PHP's [`strtotime()`](https://www.php.net/strtotime).
|
||||
|
||||
Attribute Name Type Required Default Description
|
||||
----------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
prefix string No Time\_ What to prefix the var name with
|
||||
time [timestamp](https://www.php.net/function.time), [DateTime](https://www.php.net/class.DateTime), mysql timestamp or any string parsable by [`strtotime()`](https://www.php.net/strtotime), arrays as produced by this function if field\_array is set. No current [timestamp](https://www.php.net/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.
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Default | Description |
|
||||
|-----------------------|--------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| prefix | Time\_ | What to prefix the var name with |
|
||||
| time | current [timestamp](https://www.php.net/function.time) | What date/time to pre-select. Accepts [timestamp](https://www.php.net/function.time), [DateTime](https://www.php.net/class.DateTime), mysql timestamp or any string parsable by [`strtotime()`](https://www.php.net/strtotime). 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 | TRUE | Whether or not to display hours |
|
||||
| display\_minutes | TRUE | Whether or not to display minutes |
|
||||
| display\_seconds | TRUE | Whether or not to display seconds |
|
||||
| display\_meridian | TRUE | Whether or not to display meridian (am/pm) |
|
||||
| use\_24\_hours | TRUE | Whether or not to use 24 hour clock |
|
||||
| minute\_interval | 1 | Number interval in minute dropdown |
|
||||
| second\_interval | 1 | Number interval in second dropdown |
|
||||
| hour\_format | \%02d | What format the hour label should be in (sprintf) |
|
||||
| hour\_value\_format | \%20d | What format the hour value should be in (sprintf) |
|
||||
| minute\_format | \%02d | What format the minute label should be in (sprintf) |
|
||||
| minute\_value\_format | \%20d | What format the minute value should be in (sprintf) |
|
||||
| second\_format | \%02d | What format the second label should be in (sprintf) |
|
||||
| second\_value\_format | \%20d | What format the second value should be in (sprintf) |
|
||||
| field\_array | n/a | Outputs values to array of this name |
|
||||
| all\_extra | null | Adds extra attributes to select/input tags if given |
|
||||
| hour\_extra | null | Adds extra attributes to select/input tags if given |
|
||||
| minute\_extra | null | Adds extra attributes to select/input tags if given |
|
||||
| second\_extra | null | Adds extra attributes to select/input tags if given |
|
||||
| meridian\_extra | null | Adds extra attributes to select/input tags if given |
|
||||
| field\_separator | \\n | String printed between different fields |
|
||||
| option\_separator | \\n | String printed between different options of a field |
|
||||
| all\_id | null | Adds id-attribute to all select/input tags if given |
|
||||
| hour\_id | null | Adds id-attribute to select/input tags if given |
|
||||
| minute\_id | null | Adds id-attribute to select/input tags if given |
|
||||
| second\_id | null | Adds id-attribute to select/input tags if given |
|
||||
| meridian\_id | null | Adds id-attribute to select/input tags if given |
|
||||
| all\_empty | 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 | 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 | 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 | 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 | 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}
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```smarty
|
||||
{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">
|
||||
```html
|
||||
<select name="Time_Hour">
|
||||
<option value="00">00</option>
|
||||
<option value="01">01</option>
|
||||
... snipped ....
|
||||
@@ -63,8 +66,8 @@ At 9:20 and 23 seconds in the morning the template above would output:
|
||||
... snipped ....
|
||||
<option value="22">22</option>
|
||||
<option value="23">23</option>
|
||||
</select>
|
||||
<select name="Time_Minute">
|
||||
</select>
|
||||
<select name="Time_Minute">
|
||||
<option value="00">00</option>
|
||||
<option value="01">01</option>
|
||||
... snipped ....
|
||||
@@ -74,8 +77,8 @@ At 9:20 and 23 seconds in the morning the template above would output:
|
||||
... snipped ....
|
||||
<option value="58">58</option>
|
||||
<option value="59">59</option>
|
||||
</select>
|
||||
<select name="Time_Second">
|
||||
</select>
|
||||
<select name="Time_Second">
|
||||
<option value="00">00</option>
|
||||
<option value="01">01</option>
|
||||
... snipped ....
|
||||
@@ -85,14 +88,13 @@ At 9:20 and 23 seconds in the morning the template above would output:
|
||||
... snipped ....
|
||||
<option value="58">58</option>
|
||||
<option value="59">59</option>
|
||||
</select>
|
||||
<select name="Time_Meridian">
|
||||
</select>
|
||||
<select name="Time_Meridian">
|
||||
<option value="am" selected>AM</option>
|
||||
<option value="pm">PM</option>
|
||||
</select>
|
||||
</select>
|
||||
```
|
||||
|
||||
|
||||
|
||||
See also [`$smarty.now`](#language.variables.smarty.now),
|
||||
[`{html_select_date}`](#language.function.html.select.date) and the
|
||||
[date tips page](#tips.dates).
|
||||
See also [`$smarty.now`](../language-variables/language-variables-smarty.md#smartynow-languagevariablessmartynow),
|
||||
[`{html_select_date}`](language-function-html-select-date.md) and the
|
||||
[date tips page](../../appendixes/tips.md#dates).
|
||||
|
@@ -1,23 +1,24 @@
|
||||
{html\_table} {#language.function.html.table}
|
||||
=============
|
||||
# {html_table}
|
||||
|
||||
`{html_table}` is a [custom function](#language.custom.functions) that
|
||||
`{html_table}` is a [custom function](index.md) 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 * * 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)
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| loop | Yes | Array of data to loop through |
|
||||
| cols | No | 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 | No | 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 | No | 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 | No | Text to be used for the `<caption>` element of the table |
|
||||
| table\_attr | No | Attributes for `<table>` tag (defaults to 'border="1"') |
|
||||
| th\_attr | No | Attributes for `<th>` tag (arrays are cycled) |
|
||||
| tr\_attr | No | attributes for `<tr>` tag (arrays are cycled) |
|
||||
| td\_attr | No | Attributes for `<td>` tag (arrays are cycled) |
|
||||
| trailpad | No | Value to pad the trailing cells on last row with (if any) (defaults to ' ') |
|
||||
| hdir | No | Direction of each row to be rendered. possible values: *right* (left-to-right), and *left* (right-to-left) (defaults to 'right') |
|
||||
| vdir | No | Direction of each column to be rendered. possible values: *down* (top-to-bottom), *up* (bottom-to-top) (defaults to 'down') |
|
||||
|
||||
- The `cols` attribute determines how many columns will be in the
|
||||
table.
|
||||
@@ -30,60 +31,63 @@ dumps an array of data into an HTML `<table>`.
|
||||
- `trailpad` is the value put into the trailing cells on the last
|
||||
table row if there are any present.
|
||||
|
||||
<!-- -->
|
||||
## Examples
|
||||
|
||||
|
||||
<?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');
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?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">
|
||||
** Example 1 **
|
||||
```smarty
|
||||
{html_table loop=$data}
|
||||
```
|
||||
```html
|
||||
<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>
|
||||
<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>
|
||||
</table>
|
||||
```
|
||||
|
||||
|
||||
{**** Example Two ****}
|
||||
{html_table loop=$data cols=4 table_attr='border="0"'}
|
||||
|
||||
<table border="0">
|
||||
** Example 2 **
|
||||
```smarty
|
||||
{html_table loop=$data cols=4 table_attr='border="0"'}
|
||||
```
|
||||
```html
|
||||
<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> </td><td> </td><td> </td></tr>
|
||||
<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> </td><td> </td><td> </td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</table>
|
||||
```
|
||||
|
||||
|
||||
{**** Example Three ****}
|
||||
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
|
||||
|
||||
<table border="1">
|
||||
** Example 3 **
|
||||
```smarty
|
||||
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
|
||||
```
|
||||
```html
|
||||
<table border="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>first</th><th>second</th><th>third</th><th>fourth</th>
|
||||
</tr>
|
||||
<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> </td><td> </td><td> </td></tr>
|
||||
<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> </td><td> </td><td> </td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</table>
|
||||
```
|
||||
|
||||
|
@@ -1,56 +1,61 @@
|
||||
{mailto} {#language.function.mailto}
|
||||
========
|
||||
# {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.
|
||||
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|-----------------------------------------------------------------------------------------------|
|
||||
| address | Yes | The e-mail address |
|
||||
| text | No | The text to display, default is the e-mail address |
|
||||
| encode | No | How to encode the e-mail. Can be one of `none`, `hex`, `javascript` or `javascript_charcode`. |
|
||||
| cc | No | Email addresses to carbon copy, separate entries by a comma. |
|
||||
| bcc | No | Email addresses to blind carbon copy, separate entries by a comma |
|
||||
| subject | No | Email subject |
|
||||
| newsgroups | No | Newsgroups to post to, separate entries by a comma. |
|
||||
| followupto | No | Addresses to follow up to, separate entries by a comma. |
|
||||
| extra | No | Any extra information you want passed to the link, such as style sheet classes |
|
||||
|
||||
> **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
|
||||
|
||||
## Examples
|
||||
|
||||
{mailto address="me@example.com"}
|
||||
<a href="mailto:me@example.com" >me@example.com</a>
|
||||
```smarty
|
||||
{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" 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="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">m&..snipped...#x6f;m</a>
|
||||
{mailto address="me@example.com" encode="hex"}
|
||||
<a href="mailto:%6d%65.. snipped..3%6f%6d">m&..snipped...#x6f;m</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" 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" 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" 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>
|
||||
{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).
|
||||
See also [`escape`](../language-modifiers/language-modifier-escape.md),
|
||||
[`{textformat}`](../language-custom-functions/language-function-textformat.md) and [obfuscating email
|
||||
addresses](../../appendixes/tips.md#obfuscating-e-mail-addresses).
|
||||
|
@@ -1,9 +1,18 @@
|
||||
{math} {#language.function.math}
|
||||
======
|
||||
# {math}
|
||||
|
||||
`{math}` allows the template designer to do math equations in the
|
||||
template.
|
||||
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Required | Description |
|
||||
|----------------|----------|--------------------------------------------------|
|
||||
| equation | Yes | The equation to execute |
|
||||
| format | No | The format of the result (sprintf) |
|
||||
| var | Yes | Equation variable value |
|
||||
| assign | No | Template variable the output will be assigned to |
|
||||
| \[var \...\] | Yes | Equation variable value |
|
||||
|
||||
- Any numeric template variables may be used in the equations, and the
|
||||
result is printed in place of the tag.
|
||||
|
||||
@@ -24,81 +33,67 @@ template.
|
||||
> `{math}` is an expensive function in performance due to its use of the
|
||||
> php [`eval()`](https://www.php.net/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
|
||||
> in the script and [`assign()`](../../programmers/api-functions/api-assign.md) the results to the
|
||||
> template. Definitely avoid repetitive `{math}` function calls, eg
|
||||
> within [`{section}`](#language.function.section) loops.
|
||||
> within [`{section}`](../language-builtin-functions/language-function-section.md) 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
|
||||
## Examples
|
||||
|
||||
**Example a:**
|
||||
**Example 1**
|
||||
```smarty
|
||||
|
||||
{* $height=4, $width=5 *}
|
||||
|
||||
{* $height=4, $width=5 *}
|
||||
|
||||
{math equation="x + y" x=$height y=$width}
|
||||
|
||||
{math equation="x + y" x=$height y=$width}
|
||||
```
|
||||
|
||||
The above example will output:
|
||||
|
||||
```
|
||||
9
|
||||
```
|
||||
|
||||
|
||||
**Example 2**
|
||||
|
||||
```smarty
|
||||
{* $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:
|
||||
|
||||
|
||||
9
|
||||
|
||||
```
|
||||
100
|
||||
```
|
||||
|
||||
**Example 3**
|
||||
|
||||
**Example b:**
|
||||
```smarty
|
||||
{* you can use parenthesis *}
|
||||
|
||||
|
||||
{* $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#}
|
||||
|
||||
|
||||
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
||||
```
|
||||
|
||||
The above example will output:
|
||||
|
||||
```
|
||||
6
|
||||
```
|
||||
|
||||
100
|
||||
**Example 4**
|
||||
|
||||
```smarty
|
||||
{* you can supply a format parameter in sprintf format *}
|
||||
|
||||
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
||||
```
|
||||
|
||||
|
||||
**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
|
||||
|
||||
|
||||
```
|
||||
9.44
|
||||
```
|
||||
|
@@ -1,190 +1,182 @@
|
||||
{textformat} {#language.function.textformat}
|
||||
============
|
||||
# {textformat}
|
||||
|
||||
`{textformat}` is a [block function](#plugins.block.functions) used to
|
||||
`{textformat}` is a [block function](../../programmers/plugins/plugins-block-functions.md) 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
|
||||
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
|
||||
## Attributes
|
||||
|
||||
| Attribute Name | Default | Description |
|
||||
|----------------|------------------|----------------------------------------------------------------------------------------|
|
||||
| style | *n/a* | Preset style |
|
||||
| indent | *0* | The number of chars to indent every line |
|
||||
| indent\_first | *0* | The number of chars to indent the first line |
|
||||
| indent\_char | *(single space)* | The character (or string of chars) to indent with |
|
||||
| wrap | *80* | How many characters to wrap each line to |
|
||||
| wrap\_char | *\\n* | The character (or string of chars) to break each line with |
|
||||
| wrap\_cut | *FALSE* | If TRUE, wrap will break the line at the exact character instead of at a word boundary |
|
||||
| assign | *n/a* | The template variable the output will be assigned to |
|
||||
|
||||
## Examples
|
||||
|
||||
```smarty
|
||||
{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.
|
||||
```
|
||||
|
||||
```smarty
|
||||
{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}
|
||||
```smarty
|
||||
{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 foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
|
||||
This is bar.
|
||||
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.
|
||||
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}
|
||||
|
||||
|
||||
|
||||
{/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 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.
|
||||
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.
|
||||
```
|
||||
|
||||
|
||||
```smarty
|
||||
{textformat style="email"}
|
||||
|
||||
{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 foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is foo.
|
||||
This is bar.
|
||||
|
||||
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.
|
||||
|
||||
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}
|
||||
|
||||
|
||||
|
||||
{/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 foo. This is foo. This is
|
||||
foo. This is foo. This is foo. This
|
||||
is foo.
|
||||
This is bar.
|
||||
|
||||
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.
|
||||
```
|
||||
|
||||
|
||||
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).
|
||||
See also [`{strip}`](../language-builtin-functions/language-function-strip.md) and
|
||||
[`wordwrap`](../language-modifiers/language-modifier-wordwrap.md).
|
||||
|
Reference in New Issue
Block a user