mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
Finished improving designers docs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Escaping Smarty Parsing
|
||||
# Escaping Smarty parsing
|
||||
|
||||
It is sometimes desirable or even necessary to have Smarty ignore
|
||||
sections it would otherwise parse. A classic example is embedding
|
||||
|
@@ -22,7 +22,7 @@ within delimiters like so: `{funcname attr1="val1" attr2="val2"}`.
|
||||
```
|
||||
|
||||
- Both [built-in functions](../language-builtin-functions/index.md) and [custom
|
||||
functions](../language-custom-functions.md) have the same syntax within
|
||||
functions](../language-custom-functions/index.md) have the same syntax within
|
||||
templates.
|
||||
|
||||
- Built-in functions are the **inner** workings of Smarty, such as
|
||||
|
@@ -4,7 +4,7 @@ Smarty comes with several built-in functions. These built-in functions
|
||||
are the integral part of the smarty template engine. They are compiled
|
||||
into corresponding inline PHP code for maximum performance.
|
||||
|
||||
You cannot create your own [custom functions](../language-custom-functions.md) with the same name; and you
|
||||
You cannot create your own [custom functions](../language-custom-functions/index.md) with the same name; and you
|
||||
should not need to modify the built-in functions.
|
||||
|
||||
A few of these functions have an `assign` attribute which collects the
|
||||
@@ -12,7 +12,7 @@ result the function to a named template variable instead of being
|
||||
output; much like the [`{assign}`](language-function-assign.md) function.
|
||||
|
||||
- [{append}](language-function-append.md)
|
||||
- [{assign}](language-function-assign.md) or [{$var=...}](language-function-shortform-assign.md)
|
||||
- [{assign} or {$var=...}](language-function-assign.md)
|
||||
- [{block}](language-function-block.md)
|
||||
- [{call}](language-function-call.md)
|
||||
- [{capture}](language-function-capture.md)
|
||||
|
@@ -68,6 +68,6 @@ I say just hello world
|
||||
|
||||
|
||||
See also [`$smarty.capture`](../language-variables/language-variables-smarty.md#smartycapture-languagevariablessmartycapture),
|
||||
[`{eval}`](./language-function-eval.md),
|
||||
[`{fetch}`](./language-function-fetch.md), [`fetch()`](../../programmers/api-functions/api-fetch.md) and
|
||||
[`{eval}`](../language-custom-functions/language-function-eval.md),
|
||||
[`{fetch}`](../language-custom-functions/language-function-fetch.md), [`fetch()`](../../programmers/api-functions/api-fetch.md) and
|
||||
[`{assign}`](./language-function-assign.md).
|
||||
|
@@ -1,19 +0,0 @@
|
||||
# Custom Functions
|
||||
|
||||
Smarty comes with several custom plugin functions that you can use in
|
||||
the templates.
|
||||
|
||||
- [{counter}](./language-custom-functions/language-function-counter.md)
|
||||
- [{cycle}](./language-custom-functions/language-function-cycle.md)
|
||||
- [{eval}](./language-custom-functions/language-function-eval.md)
|
||||
- [{fetch}](./language-custom-functions/language-function-fetch.md)
|
||||
- [{html_checkboxes}](./language-custom-functions/language-function-html-checkboxes.md)
|
||||
- [{html_image}](./language-custom-functions/language-function-html-image.md)
|
||||
- [{html_options}](./language-custom-functions/language-function-html-options.md)
|
||||
- [{html_radios}](./language-custom-functions/language-function-html-radios.md)
|
||||
- [{html_select_date}](./language-custom-functions/language-function-html-select-date.md)
|
||||
- [{html_select_time}](./language-custom-functions/language-function-html-select-time.md)
|
||||
- [{html_table}](./language-custom-functions/language-function-html-table.md)
|
||||
- [{mailto}](./language-custom-functions/language-function-mailto.md)
|
||||
- [{math}](./language-custom-functions/language-function-math.md)
|
||||
- [{textformat}](./language-custom-functions/language-function-textformat.md)
|
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"}
|
||||
{mailto address="me@example.com" encode="javascript"}
|
||||
<script>
|
||||
eval(unescape('%64%6f% ... snipped ...%61%3e%27%29%3b'))
|
||||
</script>
|
||||
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"}
|
||||
{mailto address="me@example.com" encode="javascript_charcode"}
|
||||
<script>
|
||||
{document.write(String.fromCharCode(60,97, ... snipped ....60,47,97,62))}
|
||||
</script>
|
||||
{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).
|
||||
|
@@ -1,39 +1,39 @@
|
||||
# Variable Modifiers
|
||||
|
||||
Variable modifiers can be applied to
|
||||
[variables](./language-variables.md), [custom functions](./language-custom-functions.md)
|
||||
[variables](../language-variables/index.md), [custom functions](../language-custom-functions/index.md)
|
||||
or strings. To apply a modifier,
|
||||
specify the value followed by a `|` (pipe) and the modifier name. A
|
||||
modifier may accept additional parameters that affect its behavior.
|
||||
These parameters follow the modifier name and are separated by a `:`
|
||||
(colon). Also, *all php-functions can be used as modifiers implicitly*
|
||||
(more below) and modifiers can be
|
||||
[combined](./language-combining-modifiers.md).
|
||||
[combined](../language-combining-modifiers.md).
|
||||
|
||||
- [capitalize](./language-modifiers/language-modifier-capitalize.md)
|
||||
- [cat](./language-modifiers/language-modifier-cat.md)
|
||||
- [count_characters](./language-modifiers/language-modifier-count-characters.md)
|
||||
- [count_paragraphs](./language-modifiers/language-modifier-count-paragraphs.md)
|
||||
- [count_sentences](./language-modifiers/language-modifier-count-sentences.md)
|
||||
- [count_words](./language-modifiers/language-modifier-count-words.md)
|
||||
- [date_format](./language-modifiers/language-modifier-date-format.md)
|
||||
- [default](./language-modifiers/language-modifier-default.md)
|
||||
- [escape](./language-modifiers/language-modifier-escape.md)
|
||||
- [from_charset](./language-modifiers/language-modifier-from-charset.md)
|
||||
- [indent](./language-modifiers/language-modifier-indent.md)
|
||||
- [lower](./language-modifiers/language-modifier-lower.md)
|
||||
- [nl2br](./language-modifiers/language-modifier-nl2br.md)
|
||||
- [regex_replace](./language-modifiers/language-modifier-regex-replace.md)
|
||||
- [replace](./language-modifiers/language-modifier-replace.md)
|
||||
- [spacify](./language-modifiers/language-modifier-spacify.md)
|
||||
- [string_format](./language-modifiers/language-modifier-string-format.md)
|
||||
- [strip](./language-modifiers/language-modifier-strip.md)
|
||||
- [strip_tags](./language-modifiers/language-modifier-strip-tags.md)
|
||||
- [to_charset](./language-modifiers/language-modifier-to-charset.md)
|
||||
- [truncate](./language-modifiers/language-modifier-truncate.md)
|
||||
- [unescape](./language-modifiers/language-modifier-unescape.md)
|
||||
- [upper](./language-modifiers/language-modifier-upper.md)
|
||||
- [wordwrap](./language-modifiers/language-modifier-wordwrap.md)
|
||||
- [capitalize](language-modifier-capitalize.md)
|
||||
- [cat](language-modifier-cat.md)
|
||||
- [count_characters](language-modifier-count-characters.md)
|
||||
- [count_paragraphs](language-modifier-count-paragraphs.md)
|
||||
- [count_sentences](language-modifier-count-sentences.md)
|
||||
- [count_words](language-modifier-count-words.md)
|
||||
- [date_format](language-modifier-date-format.md)
|
||||
- [default](language-modifier-default.md)
|
||||
- [escape](language-modifier-escape.md)
|
||||
- [from_charset](language-modifier-from-charset.md)
|
||||
- [indent](language-modifier-indent.md)
|
||||
- [lower](language-modifier-lower.md)
|
||||
- [nl2br](language-modifier-nl2br.md)
|
||||
- [regex_replace](language-modifier-regex-replace.md)
|
||||
- [replace](language-modifier-replace.md)
|
||||
- [spacify](language-modifier-spacify.md)
|
||||
- [string_format](language-modifier-string-format.md)
|
||||
- [strip](language-modifier-strip.md)
|
||||
- [strip_tags](language-modifier-strip-tags.md)
|
||||
- [to_charset](language-modifier-to-charset.md)
|
||||
- [truncate](language-modifier-truncate.md)
|
||||
- [unescape](language-modifier-unescape.md)
|
||||
- [upper](language-modifier-upper.md)
|
||||
- [wordwrap](language-modifier-wordwrap.md)
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -100,6 +100,6 @@ These parameters follow the modifier name and are separated by a `:`
|
||||
with the [`registerPlugin()`](../programmers/api-functions/api-register-plugin.md)
|
||||
function.
|
||||
|
||||
See also [`registerPlugin()`](../programmers/api-functions/api-register-plugin.md), [combining
|
||||
modifiers](./language-combining-modifiers.md). and [extending smarty with
|
||||
plugins](../programmers/plugins.md)
|
||||
See also [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md), [combining
|
||||
modifiers](../language-combining-modifiers.md). and [extending smarty with
|
||||
plugins](../../programmers/plugins.md)
|
@@ -1,41 +1,49 @@
|
||||
capitalize {#language.modifier.capitalize}
|
||||
==========
|
||||
# capitalize
|
||||
|
||||
This is used to capitalize the first letter of all words in a variable.
|
||||
This is similar to the PHP [`ucwords()`](https://www.php.net/ucwords)
|
||||
function.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- --------- -----------------------------------------------------------------------------------------------------------
|
||||
1 boolean No FALSE This determines whether or not words with digits will be uppercased
|
||||
2 boolean No FALSE This determines whether or not Capital letters within words should be lowercased, e.g. \"aAa\" to \"Aaa\"
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|capitalize}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|---------|----------|-------------------------------------------------------------------------------------------------------|
|
||||
| 1 | boolean | No | This determines whether or not words with digits will be uppercased |
|
||||
| 2 | boolean | No | This determines whether or not Capital letters within words should be lowercased, e.g. "aAa" to "Aaa" |
|
||||
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');
|
||||
|
||||
?>
|
||||
|
||||
```
|
||||
|
||||
|
||||
Where the template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|capitalize}
|
||||
{$articleTitle|capitalize:true}
|
||||
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
```
|
||||
next x-men film, x3, delayed.
|
||||
Next X-Men Film, x3, Delayed.
|
||||
Next X-Men Film, X3, Delayed.
|
||||
|
||||
```
|
||||
|
||||
|
||||
See also [`lower`](#language.modifier.lower) and
|
||||
[`upper`](#language.modifier.upper)
|
||||
See also [`lower`](language-modifier-lower.md) and
|
||||
[`upper`](language-modifier-upper.md)
|
||||
|
@@ -1,31 +1,36 @@
|
||||
cat {#language.modifier.cat}
|
||||
===
|
||||
# cat
|
||||
|
||||
This value is concatenated to the given variable.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- -----------------------------------------------
|
||||
1 string No *empty* This value to catenate to the given variable.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|cat:' units'}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|--------|----------|--------------------------------------------------|
|
||||
| 1 | string | No | This value to concatenate to the given variable. |
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Psychics predict world didn't end");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle|cat:' yesterday.'}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
```
|
||||
Psychics predict world didn't end yesterday.
|
||||
|
||||
```
|
||||
|
||||
|
@@ -1,39 +1,43 @@
|
||||
count\_characters {#language.modifier.count.characters}
|
||||
=================
|
||||
# count_characters
|
||||
|
||||
This is used to count the number of characters in a variable.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- --------- -------------------------------------------------------------------------------
|
||||
1 boolean No FALSE This determines whether or not to include whitespace characters in the count.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_characters}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|---------|----------|------------------------------------------------------------------------|
|
||||
| 1 | boolean | No | This determines whether to include whitespace characters in the count. |
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Cold Wave Linked to Temperatures.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|count_characters}
|
||||
{$articleTitle|count_characters:true}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
```
|
||||
Cold Wave Linked to Temperatures.
|
||||
29
|
||||
33
|
||||
|
||||
```
|
||||
|
||||
|
||||
See also [`count_words`](#language.modifier.count.words),
|
||||
[`count_sentences`](#language.modifier.count.sentences) and
|
||||
[`count_paragraphs`](#language.modifier.count.paragraphs).
|
||||
See also [`count_words`](language-modifier-count-words.md),
|
||||
[`count_sentences`](language-modifier-count-sentences.md) and
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md).
|
||||
|
@@ -1,38 +1,41 @@
|
||||
count\_paragraphs {#language.modifier.count.paragraphs}
|
||||
=================
|
||||
# count_paragraphs
|
||||
|
||||
This is used to count the number of paragraphs in a variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_paragraphs}
|
||||
```
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"War Dims Hope for Peace. Child's Death Ruins Couple's Holiday.\n\n
|
||||
Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation."
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|count_paragraphs}
|
||||
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
```
|
||||
War Dims Hope for Peace. Child's Death Ruins Couple's Holiday.
|
||||
|
||||
Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
|
||||
2
|
||||
```
|
||||
|
||||
|
||||
|
||||
See also [`count_characters`](#language.modifier.count.characters),
|
||||
[`count_sentences`](#language.modifier.count.sentences) and
|
||||
[`count_words`](#language.modifier.count.words).
|
||||
See also [`count_characters`](language-modifier-count-characters.md),
|
||||
[`count_sentences`](language-modifier-count-sentences.md) and
|
||||
[`count_words`](language-modifier-count-words.md).
|
||||
|
@@ -1,37 +1,39 @@
|
||||
count\_sentences {#language.modifier.count.sentences}
|
||||
================
|
||||
# count_sentences
|
||||
|
||||
This is used to count the number of sentences in a variable. A sentence
|
||||
being delimited by a dot, question- or exclamation-mark (.?!).
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_sentences}
|
||||
```
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
'Two Soviet Ships Collide - One Dies.
|
||||
Enraged Cow Injures Farmer with Axe.'
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|count_sentences}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
```
|
||||
Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
|
||||
2
|
||||
|
||||
```
|
||||
|
||||
|
||||
See also [`count_characters`](#language.modifier.count.characters),
|
||||
[`count_paragraphs`](#language.modifier.count.paragraphs) and
|
||||
[`count_words`](#language.modifier.count.words).
|
||||
See also [`count_characters`](language-modifier-count-characters.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_words`](language-modifier-count-words.md).
|
||||
|
@@ -1,33 +1,35 @@
|
||||
count\_words {#language.modifier.count.words}
|
||||
============
|
||||
# count_words
|
||||
|
||||
This is used to count the number of words in a variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_words}
|
||||
```
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|count_words}
|
||||
|
||||
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
|
||||
```
|
||||
Dealers Will Hear Car Talk at Noon.
|
||||
7
|
||||
```
|
||||
|
||||
|
||||
|
||||
See also [`count_characters`](#language.modifier.count.characters),
|
||||
[`count_paragraphs`](#language.modifier.count.paragraphs) and
|
||||
[`count_sentences`](#language.modifier.count.sentences).
|
||||
See also [`count_characters`](language-modifier-count-characters.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_sentences`](language-modifier-count-sentences.md).
|
||||
|
@@ -1,5 +1,4 @@
|
||||
date\_format {#language.modifier.date.format}
|
||||
============
|
||||
# date_format
|
||||
|
||||
This formats a date and time into the given
|
||||
[`strftime()`](https://www.php.net/strftime) format. Dates can be passed to
|
||||
@@ -11,10 +10,17 @@ made up of month day year, parsable by php\'s
|
||||
the date passed to `date_format` is empty and a second parameter is
|
||||
passed, that will be used as the date to format.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- ------------ -------------------------------------------------
|
||||
1 string No \%b %e, %Y This is the format for the outputted date.
|
||||
2 string No n/a This is the default date if the input is empty.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|date_format:"%Y-%m-%d"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|--------|----------|-----------|-------------------------------------------------|
|
||||
| 1 | string | No | %b %e, %Y | This is the format for the outputted date. |
|
||||
| 2 | string | No | n/a | This is the default date if the input is empty. |
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -33,143 +39,107 @@ passed, that will be used as the date to format.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> `date_format` is essentially a wrapper to PHP\'s
|
||||
> `date_format` is essentially a wrapper to PHP's
|
||||
> [`strftime()`](https://www.php.net/strftime) function. You may have more
|
||||
> or less conversion specifiers available depending on your system\'s
|
||||
> or less conversion specifiers available depending on your system's
|
||||
> [`strftime()`](https://www.php.net/strftime) function where PHP was
|
||||
> compiled. Check your system\'s manpage for a full list of valid
|
||||
> specifiers. However, a few of the specifiers are emulated on Windows.
|
||||
> These are: %D, %e, %h, %l, %n, %r, %R, %t, %T.
|
||||
|
||||
## Examples
|
||||
|
||||
<?php
|
||||
```php
|
||||
<?php
|
||||
|
||||
$config['date'] = '%I:%M %p';
|
||||
$config['time'] = '%H:%M:%S';
|
||||
$smarty->assign('config', $config);
|
||||
$smarty->assign('yesterday', strtotime('-1 day'));
|
||||
$config['date'] = '%I:%M %p';
|
||||
$config['time'] = '%H:%M:%S';
|
||||
$smarty->assign('config', $config);
|
||||
$smarty->assign('yesterday', strtotime('-1 day'));
|
||||
|
||||
?>
|
||||
```
|
||||
|
||||
|
||||
|
||||
This template uses [`$smarty.now`](#language.variables.smarty.now) to
|
||||
This template uses [`$smarty.now`](../language-variables/language-variables-smarty.md#smartynow-languagevariablessmartynow) to
|
||||
get the current time:
|
||||
|
||||
|
||||
{$smarty.now|date_format}
|
||||
{$smarty.now|date_format:"%D"}
|
||||
{$smarty.now|date_format:$config.date}
|
||||
{$yesterday|date_format}
|
||||
{$yesterday|date_format:"%A, %B %e, %Y"}
|
||||
{$yesterday|date_format:$config.time}
|
||||
|
||||
|
||||
```smarty
|
||||
{$smarty.now|date_format}
|
||||
{$smarty.now|date_format:"%D"}
|
||||
{$smarty.now|date_format:$config.date}
|
||||
{$yesterday|date_format}
|
||||
{$yesterday|date_format:"%A, %B %e, %Y"}
|
||||
{$yesterday|date_format:$config.time}
|
||||
```
|
||||
|
||||
This above will output:
|
||||
|
||||
|
||||
Jan 1, 2022
|
||||
01/01/22
|
||||
02:33 pm
|
||||
Dec 31, 2021
|
||||
Monday, December 1, 2021
|
||||
14:33:00
|
||||
|
||||
```
|
||||
Jan 1, 2022
|
||||
01/01/22
|
||||
02:33 pm
|
||||
Dec 31, 2021
|
||||
Monday, December 1, 2021
|
||||
14:33:00
|
||||
```
|
||||
|
||||
## Conversion specifiers
|
||||
|
||||
`date_format` conversion specifiers:
|
||||
|
||||
- \%a - abbreviated weekday name according to the current locale
|
||||
|
||||
- \%A - full weekday name according to the current locale
|
||||
|
||||
- \%b - abbreviated month name according to the current locale
|
||||
|
||||
- \%B - full month name according to the current locale
|
||||
|
||||
- \%c - preferred date and time representation for the current locale
|
||||
|
||||
- \%C - century number (the year divided by 100 and truncated to an
|
||||
- %a - abbreviated weekday name according to the current locale
|
||||
- %A - full weekday name according to the current locale
|
||||
- %b - abbreviated month name according to the current locale
|
||||
- %B - full month name according to the current locale
|
||||
- %c - preferred date and time representation for the current locale
|
||||
- %C - century number (the year divided by 100 and truncated to an
|
||||
integer, range 00 to 99)
|
||||
|
||||
- \%d - day of the month as a decimal number (range 01 to 31)
|
||||
|
||||
- \%D - same as %m/%d/%y
|
||||
|
||||
- \%e - day of the month as a decimal number, a single digit is
|
||||
- %d - day of the month as a decimal number (range 01 to 31)
|
||||
- %D - same as %m/%d/%y
|
||||
- %e - day of the month as a decimal number, a single digit is
|
||||
preceded by a space (range 1 to 31)
|
||||
|
||||
- \%g - Week-based year within century \[00,99\]
|
||||
|
||||
- \%G - Week-based year, including the century \[0000,9999\]
|
||||
|
||||
- \%h - same as %b
|
||||
|
||||
- \%H - hour as a decimal number using a 24-hour clock (range 00
|
||||
- %g - Week-based year within century \[00,99\]
|
||||
- %G - Week-based year, including the century \[0000,9999\]
|
||||
- %h - same as %b
|
||||
- %H - hour as a decimal number using a 24-hour clock (range 00
|
||||
to 23)
|
||||
|
||||
- \%I - hour as a decimal number using a 12-hour clock (range 01
|
||||
- %I - hour as a decimal number using a 12-hour clock (range 01
|
||||
to 12)
|
||||
|
||||
- \%j - day of the year as a decimal number (range 001 to 366)
|
||||
|
||||
- \%k - Hour (24-hour clock) single digits are preceded by a blank.
|
||||
- %j - day of the year as a decimal number (range 001 to 366)
|
||||
- %k - Hour (24-hour clock) single digits are preceded by a blank.
|
||||
(range 0 to 23)
|
||||
|
||||
- \%l - hour as a decimal number using a 12-hour clock, single digits
|
||||
- %l - hour as a decimal number using a 12-hour clock, single digits
|
||||
preceded by a space (range 1 to 12)
|
||||
|
||||
- \%m - month as a decimal number (range 01 to 12)
|
||||
|
||||
- \%M - minute as a decimal number
|
||||
|
||||
- \%n - newline character
|
||||
|
||||
- \%p - either \`am\' or \`pm\' according to the given time value, or
|
||||
- %m - month as a decimal number (range 01 to 12)
|
||||
- %M - minute as a decimal number
|
||||
- %n - newline character
|
||||
- %p - either 'am' or 'pm' according to the given time value, or
|
||||
the corresponding strings for the current locale
|
||||
|
||||
- \%r - time in a.m. and p.m. notation
|
||||
|
||||
- \%R - time in 24 hour notation
|
||||
|
||||
- \%S - second as a decimal number
|
||||
|
||||
- \%t - tab character
|
||||
|
||||
- \%T - current time, equal to %H:%M:%S
|
||||
|
||||
- \%u - weekday as a decimal number \[1,7\], with 1 representing
|
||||
- %r - time in a.m. and p.m. notation
|
||||
- %R - time in 24 hour notation
|
||||
- %S - second as a decimal number
|
||||
- %t - tab character
|
||||
- %T - current time, equal to %H:%M:%S
|
||||
- %u - weekday as a decimal number \[1,7\], with 1 representing
|
||||
Monday
|
||||
|
||||
- \%U - week number of the current year as a decimal number, starting
|
||||
- %U - week number of the current year as a decimal number, starting
|
||||
with the first Sunday as the first day of the first week
|
||||
|
||||
- \%V - The ISO 8601:1988 week number of the current year as a decimal
|
||||
- %V - The ISO 8601:1988 week number of the current year as a decimal
|
||||
number, range 01 to 53, where week 1 is the first week that has at
|
||||
least 4 days in the current year, and with Monday as the first day
|
||||
of the week.
|
||||
|
||||
- \%w - day of the week as a decimal, Sunday being 0
|
||||
|
||||
- \%W - week number of the current year as a decimal number, starting
|
||||
- %w - day of the week as a decimal, Sunday being 0
|
||||
- %W - week number of the current year as a decimal number, starting
|
||||
with the first Monday as the first day of the first week
|
||||
|
||||
- \%x - preferred date representation for the current locale without
|
||||
- %x - preferred date representation for the current locale without
|
||||
the time
|
||||
|
||||
- \%X - preferred time representation for the current locale without
|
||||
- %X - preferred time representation for the current locale without
|
||||
the date
|
||||
- %y - year as a decimal number without a century (range 00 to 99)
|
||||
- %Y - year as a decimal number including the century
|
||||
- %Z - time zone or name or abbreviation
|
||||
- %% - a literal '%' character
|
||||
|
||||
- \%y - year as a decimal number without a century (range 00 to 99)
|
||||
|
||||
- \%Y - year as a decimal number including the century
|
||||
|
||||
- \%Z - time zone or name or abbreviation
|
||||
|
||||
- \%% - a literal \`%\' character
|
||||
|
||||
See also [`$smarty.now`](#language.variables.smarty.now),
|
||||
See also [`$smarty.now`](../language-variables/language-variables-smarty.md#smartynow-languagevariablessmartynow),
|
||||
[`strftime()`](https://www.php.net/strftime),
|
||||
[`{html_select_date}`](#language.function.html.select.date) and the
|
||||
[date tips](#tips.dates) page.
|
||||
[`{html_select_date}`](../language-custom-functions/language-function-html-select-date.md) and the
|
||||
[date tips](../../appendixes/tips.md#dates) page.
|
||||
|
@@ -1,41 +1,45 @@
|
||||
default {#language.modifier.default}
|
||||
=======
|
||||
# default
|
||||
|
||||
This is used to set a default value for a variable. If the variable is
|
||||
unset or an empty string, the given default value is printed instead.
|
||||
Default takes the one argument.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- ---------------------------------------------------------------
|
||||
1 string No *empty* This is the default value to output if the variable is empty.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|default:"(none)"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter | Type | Required | Default | Description |
|
||||
|-----------|--------|----------|---------|---------------------------------------------------------------|
|
||||
| 1 | string | No | *empty* | This is the default value to output if the variable is empty. |
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
|
||||
$smarty->assign('email', '');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle|default:'no title'}
|
||||
{$myTitle|default:'no title'}
|
||||
{$email|default:'No email address available'}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle|default:'no title'}
|
||||
{$myTitle|default:'no title'}
|
||||
{$email|default:'No email address available'}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Dealers Will Hear Car Talk at Noon.
|
||||
no title
|
||||
No email address available
|
||||
```
|
||||
|
||||
Dealers Will Hear Car Talk at Noon.
|
||||
no title
|
||||
No email address available
|
||||
|
||||
|
||||
|
||||
See also the [default variable handling](#tips.default.var.handling) and
|
||||
the [blank variable handling](#tips.blank.var.handling) pages.
|
||||
See also the [default variable handling](../../appendixes/tips.md#default-variable-handling) and
|
||||
the [blank variable handling](../../appendixes/tips.md#blank-variable-handling) pages.
|
||||
|
@@ -1,74 +1,78 @@
|
||||
escape {#language.modifier.escape}
|
||||
======
|
||||
# escape
|
||||
|
||||
`escape` is used to encode or escape a variable to `html`, `url`,
|
||||
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
|
||||
its `html`.
|
||||
|
||||
Parameter Position Type Required Possible Values Default Description
|
||||
-------------------- --------- ---------- ------------------------------------------------------------------------------------------------------------ --------- -------------------------------------------------------------------------------------
|
||||
1 string No `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail` `html` This is the escape format to use.
|
||||
2 string No `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) `UTF-8` The character set encoding passed to htmlentities() et. al.
|
||||
3 boolean No FALSE TRUE Double encode entites from & to &amp; (applys to `html` and `htmlall` only)
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|escape}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Possible Values | Default | Description |
|
||||
|--------------------|---------|----------|----------------------------------------------------------------------------------------------------------------|---------|--------------------------------------------------------------------------------------|
|
||||
| 1 | string | No | `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail` | `html` | This is the escape format to use. |
|
||||
| 2 | string | No | `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) | `UTF-8` | The character set encoding passed to htmlentities() et. al. |
|
||||
| 3 | boolean | No | FALSE | TRUE | Double encode entities from & to &amp; (applies to `html` and `htmlall` only) |
|
||||
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"'Stiff Opposition Expected to Casketless Funeral Plan'"
|
||||
);
|
||||
$smarty->assign('EmailAddress','smarty@example.com');
|
||||
```php
|
||||
<?php
|
||||
|
||||
?>
|
||||
$smarty->assign('articleTitle',
|
||||
"'Stiff Opposition Expected to Casketless Funeral Plan'"
|
||||
);
|
||||
$smarty->assign('EmailAddress','smarty@example.com');
|
||||
|
||||
```
|
||||
|
||||
|
||||
These are example `escape` template lines followed by the output
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
|
||||
{$articleTitle}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
{$articleTitle|escape}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
|
||||
{$articleTitle|escape}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
|
||||
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
|
||||
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
<a href="?title={$articleTitle|escape:'url'}">click here</a>
|
||||
<a
|
||||
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
|
||||
|
||||
<a href="?title={$articleTitle|escape:'url'}">click here</a>
|
||||
<a
|
||||
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
|
||||
{$articleTitle|escape:'quotes'}
|
||||
\'Stiff Opposition Expected to Casketless Funeral Plan\'
|
||||
|
||||
{$articleTitle|escape:'quotes'}
|
||||
\'Stiff Opposition Expected to Casketless Funeral Plan\'
|
||||
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
|
||||
{$EmailAddress|escape:'mail'} {* this converts to email to text *}
|
||||
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>
|
||||
|
||||
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
|
||||
{$EmailAddress|escape:'mail'} {* this converts to email to text *}
|
||||
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>
|
||||
{'mail@example.com'|escape:'mail'}
|
||||
smarty [AT] example [DOT] com
|
||||
|
||||
{'mail@example.com'|escape:'mail'}
|
||||
smarty [AT] example [DOT] com
|
||||
{* the "rewind" parameter registers the current location *}
|
||||
<a href="$my_path?page=foo&rewind={$my_uri|escape:url}">click here</a>
|
||||
|
||||
|
||||
|
||||
|
||||
{* the "rewind" parameter registers the current location *}
|
||||
<a href="$my_path?page=foo&rewind=$my_uri|urlencode}">click here</a>
|
||||
|
||||
|
||||
```
|
||||
|
||||
This snippet is useful for emails, but see also
|
||||
[`{mailto}`](#language.function.mailto)
|
||||
[`{mailto}`](../language-custom-functions/language-function-mailto.md)
|
||||
|
||||
```smarty
|
||||
{* email address mangled *}
|
||||
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
|
||||
```
|
||||
|
||||
{* email address mangled *}
|
||||
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
|
||||
|
||||
|
||||
|
||||
See also [escaping smarty parsing](#language.escaping),
|
||||
[`{mailto}`](#language.function.mailto) and the [obfuscating email
|
||||
addresses](#tips.obfuscating.email) page.
|
||||
See also [escaping smarty parsing](../language-basic-syntax/language-escaping.md),
|
||||
[`{mailto}`](../language-custom-functions/language-function-mailto.md) and the [obfuscating email
|
||||
addresses](../../appendixes/tips.md#obfuscating-e-mail-addresses) page.
|
||||
|
@@ -1,13 +1,14 @@
|
||||
from\_charset {#language.modifier.from_charset}
|
||||
=============
|
||||
# from_charset
|
||||
|
||||
`from_charset` is used to transcode a string from a given charset to the
|
||||
internal charset. This is the exact opposite of the [to\_charset
|
||||
modifier](#language.modifier.to_charset).
|
||||
internal charset. This is the exact opposite of the [to_charset
|
||||
modifier](language-modifier-to-charset.md).
|
||||
|
||||
Parameter Position Type Required Possible Values Default Description
|
||||
-------------------- -------- ---------- -------------------------------------------------------------------------------------------------------------------------- -------------- ---------------------------------------------------------------
|
||||
1 string No `ISO-8859-1`, `UTF-8`, and any character set supported by [`mb_convert_encoding()`](https://www.php.net/mb_convert_encoding) `ISO-8859-1` The charset encoding the value is supposed to be decoded from
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Possible Values | Default | Description |
|
||||
|--------------------|--------|----------|------------------------------------------------------------------------------------------------------------------------------|--------------|---------------------------------------------------------------|
|
||||
| 1 | string | No | `ISO-8859-1`, `UTF-8`, and any character set supported by [`mb_convert_encoding()`](https://www.php.net/mb_convert_encoding) | `ISO-8859-1` | The charset encoding the value is supposed to be decoded from |
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -15,5 +16,5 @@ modifier](#language.modifier.to_charset).
|
||||
> modifier should only be used in cases where the application cannot
|
||||
> anticipate that a certain string is required in another encoding.
|
||||
|
||||
See also [Charset Encoding](#charset), [from\_charset
|
||||
modifier](#language.modifier.from_charset).
|
||||
See also [Charset Encoding](../../programmers/charset.md), [to_charset
|
||||
modifier](language-modifier-to-charset.md).
|
||||
|
@@ -1,62 +1,67 @@
|
||||
indent {#language.modifier.indent}
|
||||
======
|
||||
# indent
|
||||
|
||||
This indents a string on each line, default is 4. As an optional
|
||||
parameter, you can specify the number of characters to indent. As an
|
||||
optional second parameter, you can specify the character to use to
|
||||
indent with eg use `"\t"` for a tab.
|
||||
indent with. For example: use `"\t"` for a tab.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- ------------- ---------------------------------------------------
|
||||
1 integer No 4 This determines how many characters to indent to.
|
||||
2 string No (one space) This is the character used to indent with.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|indent:4}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|---------|----------|-------------|---------------------------------------------------|
|
||||
| 1 | integer | No | 4 | This determines how many characters to indent to. |
|
||||
| 2 | string | No | (one space) | This is the character used to indent with. |
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
'NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.'
|
||||
);
|
||||
?>
|
||||
## Examples
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
'NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.'
|
||||
);
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|indent}
|
||||
|
||||
{$articleTitle|indent}
|
||||
|
||||
{$articleTitle|indent:10}
|
||||
|
||||
{$articleTitle|indent:1:"\t"}
|
||||
{$articleTitle|indent:10}
|
||||
|
||||
{$articleTitle|indent:1:"\t"}
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
NJ judge to rule on nude beach.
|
||||
Sun or rain expected today, dark tonight.
|
||||
Statistics show that teen pregnancy drops off significantly after 25.
|
||||
|
||||
```
|
||||
|
||||
|
||||
See also [`strip`](#language.modifier.strip),
|
||||
[`wordwrap`](#language.modifier.wordwrap) and
|
||||
[`spacify`](#language.modifier.spacify).
|
||||
See also [`strip`](language-modifier-strip.md),
|
||||
[`wordwrap`](language-modifier-wordwrap.md) and
|
||||
[`spacify`](language-modifier-spacify.md).
|
||||
|
@@ -1,33 +1,34 @@
|
||||
lower {#language.modifier.lower}
|
||||
=====
|
||||
# lower
|
||||
|
||||
This is used to lowercase a variable. This is equivalent to the PHP
|
||||
[`strtolower()`](https://www.php.net/strtolower) function.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|lower}
|
||||
```
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
|
||||
```php
|
||||
<?php
|
||||
|
||||
?>
|
||||
|
||||
|
||||
$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|lower}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|lower}
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
|
||||
Two Convicts Evade Noose, Jury Hung.
|
||||
two convicts evade noose, jury hung.
|
||||
|
||||
```
|
||||
Two Convicts Evade Noose, Jury Hung.
|
||||
two convicts evade noose, jury hung.
|
||||
```
|
||||
|
||||
|
||||
See also [`upper`](#language.modifier.upper) and
|
||||
[`capitalize`](#language.modifier.capitalize).
|
||||
See also [`upper`](language-modifier-upper.md) and
|
||||
[`capitalize`](language-modifier-capitalize.md).
|
||||
|
@@ -1,35 +1,37 @@
|
||||
nl2br
|
||||
=====
|
||||
# nl2br
|
||||
|
||||
All `"\n"` line breaks will be converted to html `<br />` tags in the
|
||||
given variable. This is equivalent to the PHP\'s
|
||||
[`nl2br()`](https://www.php.net/nl2br) function.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|nl2br}
|
||||
```
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Sun or rain expected\ntoday, dark tonight"
|
||||
);
|
||||
```php
|
||||
<?php
|
||||
|
||||
?>
|
||||
$smarty->assign('articleTitle',
|
||||
"Sun or rain expected\ntoday, dark tonight"
|
||||
);
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where the template is:
|
||||
|
||||
|
||||
{$articleTitle|nl2br}
|
||||
|
||||
```smarty
|
||||
{$articleTitle|nl2br}
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Sun or rain expected<br />today, dark tonight
|
||||
```
|
||||
|
||||
Sun or rain expected<br />today, dark tonight
|
||||
|
||||
|
||||
|
||||
See also [`word_wrap`](#language.modifier.wordwrap),
|
||||
[`count_paragraphs`](#language.modifier.count.paragraphs) and
|
||||
[`count_sentences`](#language.modifier.count.sentences).
|
||||
See also [`word_wrap`](language-modifier-wordwrap.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_sentences`](language-modifier-count-sentences.md).
|
||||
|
@@ -1,10 +1,14 @@
|
||||
regex\_replace {#language.modifier.regex.replace}
|
||||
==============
|
||||
# regex_replace
|
||||
|
||||
A regular expression search and replace on a variable. Use the
|
||||
[`preg_replace()`](https://www.php.net/preg_replace) syntax from the PHP
|
||||
manual.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|regex_replace:"/foo/":"bar"}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Although Smarty supplies this regex convenience modifier, it is
|
||||
@@ -12,40 +16,40 @@ manual.
|
||||
> functions or modifiers. Regular expressions are considered application
|
||||
> code and are not part of presentation logic.
|
||||
|
||||
Parameters
|
||||
## Parameters
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- ------------------------------------------------
|
||||
1 string Yes *n/a* This is the regular expression to be replaced.
|
||||
2 string Yes *n/a* This is the string of text to replace with.
|
||||
| Parameter Position | Type | Required | Description |
|
||||
|--------------------|--------|----------|------------------------------------------------|
|
||||
| 1 | string | Yes | This is the regular expression to be replaced. |
|
||||
| 2 | string | Yes | This is the string of text to replace with. |
|
||||
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
||||
```php
|
||||
<?php
|
||||
|
||||
?>
|
||||
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```smarty
|
||||
{* replace each carriage return, tab and new line with a space *}
|
||||
|
||||
{* replace each carriage return, tab and new line with a space *}
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
Infertility unlikely to
|
||||
be passed on, experts say.
|
||||
Infertility unlikely to be passed on, experts say.
|
||||
|
||||
```
|
||||
Infertility unlikely to
|
||||
be passed on, experts say.
|
||||
Infertility unlikely to be passed on, experts say.
|
||||
```
|
||||
|
||||
|
||||
See also [`replace`](#language.modifier.replace) and
|
||||
[`escape`](#language.modifier.escape).
|
||||
See also [`replace`](language-modifier-replace.md) and
|
||||
[`escape`](language-modifier-escape.md).
|
||||
|
@@ -1,40 +1,45 @@
|
||||
replace {#language.modifier.replace}
|
||||
=======
|
||||
# replace
|
||||
|
||||
A simple search and replace on a variable. This is equivalent to the
|
||||
PHP\'s [`str_replace()`](https://www.php.net/str_replace) function.
|
||||
PHP's [`str_replace()`](https://www.php.net/str_replace) function.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- ---------------------------------------------
|
||||
1 string Yes *n/a* This is the string of text to be replaced.
|
||||
2 string Yes *n/a* This is the string of text to replace with.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|replace:"foo":"bar"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Description |
|
||||
|--------------------|--------|----------|---------------------------------------------|
|
||||
| 1 | string | Yes | This is the string of text to be replaced. |
|
||||
| 2 | string | Yes | This is the string of text to replace with. |
|
||||
|
||||
|
||||
<?php
|
||||
## Examples
|
||||
|
||||
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||
```php
|
||||
<?php
|
||||
|
||||
?>
|
||||
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|replace:'Garden':'Vineyard'}
|
||||
{$articleTitle|replace:' ':' '}
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|replace:'Garden':'Vineyard'}
|
||||
{$articleTitle|replace:' ':' '}
|
||||
```
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Child's Stool Great for Use in Garden.
|
||||
Child's Stool Great for Use in Vineyard.
|
||||
Child's Stool Great for Use in Garden.
|
||||
```
|
||||
|
||||
Child's Stool Great for Use in Garden.
|
||||
Child's Stool Great for Use in Vineyard.
|
||||
Child's Stool Great for Use in Garden.
|
||||
|
||||
|
||||
|
||||
See also [`regex_replace`](#language.modifier.regex.replace) and
|
||||
[`escape`](#language.modifier.escape).
|
||||
See also [`regex_replace`](language-modifier-regex-replace.md) and
|
||||
[`escape`](language-modifier-escape.md).
|
||||
|
@@ -1,40 +1,44 @@
|
||||
spacify {#language.modifier.spacify}
|
||||
=======
|
||||
# spacify
|
||||
|
||||
`spacify` is a way to insert a space between every character of a
|
||||
variable. You can optionally pass a different character or string to
|
||||
insert.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- ------------- -----------------------------------------------------------------
|
||||
1 string No *one space* This what gets inserted between each character of the variable.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|spacify}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|--------|----------|-------------|-----------------------------------------------------------------|
|
||||
| 1 | string | No | *one space* | This what gets inserted between each character of the variable. |
|
||||
|
||||
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||
## Examples
|
||||
|
||||
?>
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|spacify}
|
||||
{$articleTitle|spacify:"^^"}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|spacify}
|
||||
{$articleTitle|spacify:"^^"}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Something Went Wrong in Jet Crash, Experts Say.
|
||||
S o m e t h i n g W .... snip .... s h , E x p e r t s S a y .
|
||||
S^^o^^m^^e^^t^^h^^i^^n^^g^^ .... snip .... ^^e^^r^^t^^s^^ ^^S^^a^^y^^.
|
||||
```
|
||||
|
||||
Something Went Wrong in Jet Crash, Experts Say.
|
||||
S o m e t h i n g W .... snip .... s h , E x p e r t s S a y .
|
||||
S^^o^^m^^e^^t^^h^^i^^n^^g^^ .... snip .... ^^e^^r^^t^^s^^ ^^S^^a^^y^^.
|
||||
|
||||
|
||||
|
||||
See also [`wordwrap`](#language.modifier.wordwrap) and
|
||||
[`nl2br`](#language.modifier.nl2br).
|
||||
See also [`wordwrap`](language-modifier-wordwrap.md) and
|
||||
[`nl2br`](language-modifier-nl2br.md).
|
||||
|
@@ -1,39 +1,43 @@
|
||||
string\_format {#language.modifier.string.format}
|
||||
==============
|
||||
# string_format
|
||||
|
||||
This is a way to format strings, such as decimal numbers and such. Use
|
||||
the syntax for [`sprintf()`](https://www.php.net/sprintf) for the
|
||||
formatting.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- ---------------------------------------
|
||||
1 string Yes *n/a* This is what format to use. (sprintf)
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|string_format:"%d"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Description |
|
||||
|--------------------|--------|----------|---------------------------------------|
|
||||
| 1 | string | Yes | This is what format to use. (sprintf) |
|
||||
|
||||
$smarty->assign('number', 23.5787446);
|
||||
## Examples
|
||||
|
||||
?>
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
$smarty->assign('number', 23.5787446);
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$number}
|
||||
{$number|string_format:"%.2f"}
|
||||
{$number|string_format:"%d"}
|
||||
|
||||
|
||||
```smarty
|
||||
{$number}
|
||||
{$number|string_format:"%.2f"}
|
||||
{$number|string_format:"%d"}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
23.5787446
|
||||
23.58
|
||||
23
|
||||
```
|
||||
|
||||
23.5787446
|
||||
23.58
|
||||
23
|
||||
|
||||
|
||||
|
||||
See also [`date_format`](#language.modifier.date.format).
|
||||
See also [`date_format`](language-modifier-date-format.md).
|
||||
|
@@ -1,41 +1,46 @@
|
||||
strip\_tags {#language.modifier.strip.tags}
|
||||
===========
|
||||
# strip_tags
|
||||
|
||||
This strips out markup tags, basically anything between `<` and `>`.
|
||||
This strips out HTML markup tags, basically anything between `<` and `>`.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- ------ ---------- --------- ----------------------------------------------------------------
|
||||
1 bool No TRUE This determines whether the tags are replaced by \' \' or \'\'
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|strip_tags}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|------|----------|---------|------------------------------------------------------------|
|
||||
| 1 | bool | No | TRUE | This determines whether the tags are replaced by ' ' or '' |
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Blind Woman Gets <font face=\"helvetica\">New
|
||||
Kidney</font> from Dad she Hasn't Seen in <b>years</b>."
|
||||
);
|
||||
## Examples
|
||||
|
||||
?>
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Blind Woman Gets <font face=\"helvetica\">New
|
||||
Kidney</font> from Dad she Hasn't Seen in <b>years</b>."
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip_tags} {* same as {$articleTitle|strip_tags:true} *}
|
||||
{$articleTitle|strip_tags:false}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip_tags} {* same as {$articleTitle|strip_tags:true} *}
|
||||
{$articleTitle|strip_tags:false}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```html
|
||||
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.
|
||||
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years .
|
||||
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
|
||||
```
|
||||
|
||||
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.
|
||||
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years .
|
||||
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
|
||||
|
||||
|
||||
|
||||
See also [`replace`](#language.modifier.replace) and
|
||||
[`regex_replace`](#language.modifier.regex.replace).
|
||||
See also [`replace`](language-modifier-replace.md) and
|
||||
[`regex_replace`](language-modifier-regex-replace.md).
|
||||
|
@@ -1,40 +1,42 @@
|
||||
strip {#language.modifier.strip}
|
||||
=====
|
||||
# strip
|
||||
|
||||
This replaces all spaces, newlines and tabs with a single space, or with
|
||||
the supplied string.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|strip}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If you want to strip blocks of template text, use the built-in
|
||||
> [`{strip}`](#language.function.strip) function.
|
||||
> [`{strip}`](../language-builtin-functions/language-function-strip.md) function.
|
||||
|
||||
## Examples
|
||||
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip}
|
||||
{$articleTitle|strip:' '}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip}
|
||||
{$articleTitle|strip:' '}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```html
|
||||
Grandmother of
|
||||
eight makes hole in one.
|
||||
Grandmother of eight makes hole in one.
|
||||
Grandmother of eight makes hole in one.
|
||||
```
|
||||
|
||||
Grandmother of
|
||||
eight makes hole in one.
|
||||
Grandmother of eight makes hole in one.
|
||||
Grandmother of eight makes hole in one.
|
||||
|
||||
|
||||
|
||||
See also [`{strip}`](#language.function.strip) and
|
||||
[`truncate`](#language.modifier.truncate).
|
||||
See also [`{strip}`](../language-builtin-functions/language-function-strip.md) and
|
||||
[`truncate`](language-modifier-truncate.md).
|
||||
|
@@ -1,13 +1,14 @@
|
||||
to\_charset {#language.modifier.to_charset}
|
||||
===========
|
||||
# to_charset
|
||||
|
||||
`to_charset` is used to transcode a string from the internal charset to
|
||||
a given charset. This is the exact opposite of the [from\_charset
|
||||
a given charset. This is the exact opposite of the [from_charset
|
||||
modifier](#language.modifier.from_charset).
|
||||
|
||||
Parameter Position Type Required Possible Values Default Description
|
||||
-------------------- -------- ---------- -------------------------------------------------------------------------------------------------------------------------- -------------- -------------------------------------------------------------
|
||||
1 string No `ISO-8859-1`, `UTF-8`, and any character set supported by [`mb_convert_encoding()`](https://www.php.net/mb_convert_encoding) `ISO-8859-1` The charset encoding the value is supposed to be encoded to
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Possible Values | Default | Description |
|
||||
|--------------------|--------|----------|------------------------------------------------------------------------------------------------------------------------------|--------------|-------------------------------------------------------------|
|
||||
| 1 | string | No | `ISO-8859-1`, `UTF-8`, and any character set supported by [`mb_convert_encoding()`](https://www.php.net/mb_convert_encoding) | `ISO-8859-1` | The charset encoding the value is supposed to be encoded to |
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -15,5 +16,5 @@ modifier](#language.modifier.from_charset).
|
||||
> modifier should only be used in cases where the application cannot
|
||||
> anticipate that a certain string is required in another encoding.
|
||||
|
||||
See also [Charset Encoding](#charset), [from\_charset
|
||||
modifier](#language.modifier.from_charset).
|
||||
See also [Charset Encoding](../../programmers/charset.md), [from_charset
|
||||
modifier](language-modifier-from-charset.md).
|
||||
|
@@ -1,5 +1,4 @@
|
||||
truncate {#language.modifier.truncate}
|
||||
========
|
||||
# truncate
|
||||
|
||||
This truncates a variable to a character length, the default is 80. As
|
||||
an optional second parameter, you can specify a string of text to
|
||||
@@ -9,44 +8,50 @@ string are included with the original truncation length. By default,
|
||||
cut off at the exact character length, pass the optional third parameter
|
||||
of TRUE.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- --------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
1 integer No 80 This determines how many characters to truncate to.
|
||||
2 string No \... This is a text string that replaces the truncated text. Its length is included in the truncation length setting.
|
||||
3 boolean No FALSE This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE.
|
||||
4 boolean No FALSE This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|truncate:40:"..."}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
||||
?>
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|---------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| 1 | integer | No | 80 | This determines how many characters to truncate to. |
|
||||
| 2 | string | No | \... | This is a text string that replaces the truncated text. Its length is included in the truncation length setting. |
|
||||
| 3 | boolean | No | FALSE | This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE. |
|
||||
| 4 | boolean | No | FALSE | This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored. |
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
||||
```
|
||||
|
||||
where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|truncate}
|
||||
{$articleTitle|truncate:30}
|
||||
{$articleTitle|truncate:30:""}
|
||||
{$articleTitle|truncate:30:"---"}
|
||||
{$articleTitle|truncate:30:"":true}
|
||||
{$articleTitle|truncate:30:"...":true}
|
||||
{$articleTitle|truncate:30:'..':true:true}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|truncate}
|
||||
{$articleTitle|truncate:30}
|
||||
{$articleTitle|truncate:30:""}
|
||||
{$articleTitle|truncate:30:"---"}
|
||||
{$articleTitle|truncate:30:"":true}
|
||||
{$articleTitle|truncate:30:"...":true}
|
||||
{$articleTitle|truncate:30:'..':true:true}
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
|
||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||
Two Sisters Reunite after...
|
||||
Two Sisters Reunite after
|
||||
Two Sisters Reunite after---
|
||||
Two Sisters Reunite after Eigh
|
||||
Two Sisters Reunite after E...
|
||||
Two Sisters Re..ckout Counter.
|
||||
|
||||
```
|
||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||
Two Sisters Reunite after...
|
||||
Two Sisters Reunite after
|
||||
Two Sisters Reunite after---
|
||||
Two Sisters Reunite after Eigh
|
||||
Two Sisters Reunite after E...
|
||||
Two Sisters Re..ckout Counter.
|
||||
```
|
||||
|
||||
|
@@ -1,39 +1,43 @@
|
||||
unescape {#language.modifier.unescape}
|
||||
========
|
||||
# unescape
|
||||
|
||||
`unescape` is used to decode `entity`, `html` and `htmlall`. It counters
|
||||
the effects of the [escape modifier](#language.modifier.escape) for the
|
||||
the effects of the [escape modifier](language-modifier-escape.md) for the
|
||||
given types.
|
||||
|
||||
Parameter Position Type Required Possible Values Default Description
|
||||
-------------------- -------- ---------- ------------------------------------------------------------------------------------------------------------ --------- ------------------------------------------------------------------------------------------------------------------------------
|
||||
1 string No `html`, `htmlall`, `entity`, `html` This is the escape format to use.
|
||||
2 string No `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) `UTF-8` The character set encoding passed to html\_entity\_decode() or htmlspecialchars\_decode() or mb\_convert\_encoding() et. al.
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|unescape}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Possible Values | Default | Description |
|
||||
|--------------------|--------|----------|----------------------------------------------------------------------------------------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------|
|
||||
| 1 | string | No | `html`, `htmlall`, `entity`, | `html` | This is the escape format to use. |
|
||||
| 2 | string | No | `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) | `UTF-8` | The character set encoding passed to html\_entity\_decode() or htmlspecialchars\_decode() or mb\_convert\_encoding() et. al. |
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Germans use "Ümlauts" and pay in €uro"
|
||||
);
|
||||
## Examples
|
||||
|
||||
?>
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Germans use "Ümlauts" and pay in €uro"
|
||||
);
|
||||
```
|
||||
|
||||
These are example `unescape` template lines followed by the output
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
|
||||
{$articleTitle}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
{$articleTitle|unescape:"html"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
|
||||
{$articleTitle|unescape:"html"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
{$articleTitle|unescape:"htmlall"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
```
|
||||
|
||||
{$articleTitle|unescape:"htmlall"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
|
||||
|
||||
|
||||
See also [escaping smarty parsing](#language.escaping), [escape
|
||||
modifier](#language.modifier.escape).
|
||||
See also [escaping smarty parsing](../language-basic-syntax/language-escaping.md), [escape
|
||||
modifier](language-modifier-escape.md).
|
||||
|
@@ -1,31 +1,33 @@
|
||||
upper {#language.modifier.upper}
|
||||
=====
|
||||
# upper
|
||||
|
||||
This is used to uppercase a variable. This is equivalent to the PHP
|
||||
[`strtoupper()`](https://www.php.net/strtoupper) function.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|upper}
|
||||
```
|
||||
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||
?>
|
||||
## Examples
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|upper}
|
||||
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|upper}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
If Strike isn't Settled Quickly it may Last a While.
|
||||
IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
||||
```
|
||||
|
||||
If Strike isn't Settled Quickly it may Last a While.
|
||||
IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
||||
|
||||
|
||||
|
||||
See also [`lower`](#language.modifier.lower) and
|
||||
[`capitalize`](#language.modifier.capitalize).
|
||||
See also [`lower`](lower) and
|
||||
[`capitalize`](language-modifier-capitalize.md).
|
||||
|
@@ -1,5 +1,4 @@
|
||||
wordwrap {#language.modifier.wordwrap}
|
||||
========
|
||||
# wordwrap
|
||||
|
||||
Wraps a string to a column width, the default is 80. As an optional
|
||||
second parameter, you can specify a string of text to wrap the text to
|
||||
@@ -9,61 +8,66 @@ off at the exact character length, pass the optional third parameter as
|
||||
TRUE. This is equivalent to the PHP
|
||||
[`wordwrap()`](https://www.php.net/wordwrap) function.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- --------- ---------- --------- ------------------------------------------------------------------------------------------------------
|
||||
1 integer No 80 This determines how many columns to wrap to.
|
||||
2 string No \\n This is the string used to wrap words with.
|
||||
3 boolean No FALSE This determines whether or not to wrap at a word boundary (FALSE), or at the exact character (TRUE).
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|wordwrap:30}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<?php
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|---------|----------|---------|-----------------------------------------------------------------------------------------------|
|
||||
| 1 | integer | No | 80 | This determines how many columns to wrap to. |
|
||||
| 2 | string | No | \\n | This is the string used to wrap words with. |
|
||||
| 3 | boolean | No | FALSE | This determines whether to wrap at a word boundary (FALSE), or at the exact character (TRUE). |
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Blind woman gets new kidney from dad she hasn't seen in years."
|
||||
);
|
||||
## Examples
|
||||
|
||||
?>
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Blind woman gets new kidney from dad she hasn't seen in years."
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Where template is
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|wordwrap:30}
|
||||
|
||||
{$articleTitle|wordwrap:30}
|
||||
{$articleTitle|wordwrap:20}
|
||||
|
||||
{$articleTitle|wordwrap:20}
|
||||
{$articleTitle|wordwrap:30:"<br />\n"}
|
||||
|
||||
{$articleTitle|wordwrap:30:"<br />\n"}
|
||||
|
||||
{$articleTitle|wordwrap:26:"\n":true}
|
||||
|
||||
|
||||
{$articleTitle|wordwrap:26:"\n":true}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```html
|
||||
Blind woman gets new kidney from dad she hasn't seen in years.
|
||||
|
||||
Blind woman gets new kidney from dad she hasn't seen in years.
|
||||
Blind woman gets new kidney
|
||||
from dad she hasn't seen in
|
||||
years.
|
||||
|
||||
Blind woman gets new kidney
|
||||
from dad she hasn't seen in
|
||||
years.
|
||||
Blind woman gets new
|
||||
kidney from dad she
|
||||
hasn't seen in
|
||||
years.
|
||||
|
||||
Blind woman gets new
|
||||
kidney from dad she
|
||||
hasn't seen in
|
||||
years.
|
||||
Blind woman gets new kidney<br />
|
||||
from dad she hasn't seen in<br />
|
||||
years.
|
||||
|
||||
Blind woman gets new kidney<br />
|
||||
from dad she hasn't seen in<br />
|
||||
years.
|
||||
Blind woman gets new kidn
|
||||
ey from dad she hasn't se
|
||||
en in years.
|
||||
```
|
||||
|
||||
Blind woman gets new kidn
|
||||
ey from dad she hasn't se
|
||||
en in years.
|
||||
|
||||
|
||||
|
||||
See also [`nl2br`](#language.modifier.nl2br) and
|
||||
[`{textformat}`](#language.function.textformat).
|
||||
See also [`nl2br`](language-modifier-nl2br.md) and
|
||||
[`{textformat}`](../language-custom-functions/language-function-textformat.md).
|
||||
|
@@ -1,33 +0,0 @@
|
||||
# Variables
|
||||
|
||||
Smarty has several types of variables. The type of the
|
||||
variable depends on what symbol it is prefixed or enclosed within.
|
||||
|
||||
- [Variables assigned from PHP](./language-variables/language-assigned-variables.md)
|
||||
- [Variable scopes](./language-variables/language-variable-scopes.md)
|
||||
- [Variables loaded from config files](./language-variables/language-config-variables.md)
|
||||
- [{$smarty} reserved variable](./language-variables/language-variables-smarty.md)
|
||||
|
||||
Variables in Smarty can be either displayed directly or used as
|
||||
arguments for [functions](./language-basic-syntax/language-syntax-functions.md),
|
||||
[attributes](./language-basic-syntax/language-syntax-attributes.md) and
|
||||
[modifiers](./language-modifiers.md), inside conditional expressions, etc.
|
||||
To print a variable, simply enclose it in the
|
||||
[delimiters](../programmers/api-variables/variable-left-delimiter.md) so that it is the only thing
|
||||
contained between them.
|
||||
|
||||
```smarty
|
||||
{$Name}
|
||||
|
||||
{$product.part_no} <b>{$product.description}</b>
|
||||
|
||||
{$Contacts[row].Phone}
|
||||
|
||||
<body bgcolor="{#bgcolor#}">
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> An easy way to examine assigned Smarty variables is with the
|
||||
> [debugging console](./chapter-debugging-console.md).
|
||||
|
36
docs/designers/language-variables/index.md
Normal file
36
docs/designers/language-variables/index.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Variables
|
||||
|
||||
Smarty has several types of variables. The type of the
|
||||
variable depends on what symbol it is prefixed or enclosed within.
|
||||
|
||||
- [Variables assigned from PHP](language-assigned-variables.md)
|
||||
- [Variables loaded from config files](language-config-variables.md)
|
||||
- [{$smarty} reserved variable](language-variables-smarty.md)
|
||||
|
||||
Variables in Smarty can be either displayed directly or used as
|
||||
arguments for [functions](../language-basic-syntax/language-syntax-functions.md),
|
||||
[attributes](../language-basic-syntax/language-syntax-attributes.md) and
|
||||
[modifiers](../language-modifiers/index.md), inside conditional expressions, etc.
|
||||
To print a variable, simply enclose it in the
|
||||
[delimiters](../../programmers/api-variables/variable-left-delimiter.md) so that it is the only thing
|
||||
contained between them.
|
||||
|
||||
```smarty
|
||||
{$Name}
|
||||
|
||||
{$product.part_no} <b>{$product.description}</b>
|
||||
|
||||
{$Contacts[row].Phone}
|
||||
|
||||
<body bgcolor="{#bgcolor#}">
|
||||
```
|
||||
|
||||
## Scopes
|
||||
You can assign variables to specific [variable scopes](language-variable-scopes.md).
|
||||
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> An easy way to examine assigned Smarty variables is with the
|
||||
> [debugging console](../chapter-debugging-console.md).
|
||||
|
@@ -1,142 +1,126 @@
|
||||
Variables assigned from PHP {#language.assigned.variables}
|
||||
===========================
|
||||
# Variables assigned from PHP
|
||||
|
||||
Assigned variables that are referenced by preceding them with a dollar
|
||||
Variables assigned from PHP are referenced by preceding them with a dollar
|
||||
(`$`) sign.
|
||||
|
||||
PHP code
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
<?php
|
||||
$smarty = new Smarty();
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->assign('firstname', 'Doug');
|
||||
$smarty->assign('lastname', 'Evans');
|
||||
$smarty->assign('meetingPlace', 'New York');
|
||||
|
||||
$smarty->assign('firstname', 'Doug');
|
||||
$smarty->assign('lastname', 'Evans');
|
||||
$smarty->assign('meetingPlace', 'New York');
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
?>
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
|
||||
Hello {$firstname} {$lastname}, glad to see you can make it.
|
||||
<br />
|
||||
{* this will not work as $variables are case sensitive *}
|
||||
This weeks meeting is in {$meetingplace}.
|
||||
{* this will work *}
|
||||
This weeks meeting is in {$meetingPlace}.
|
||||
|
||||
```smarty
|
||||
Hello {$firstname} {$lastname}, glad to see you can make it.
|
||||
<br />
|
||||
{* this will not work as $variables are case sensitive *}
|
||||
This weeks meeting is in {$meetingplace}.
|
||||
{* this will work *}
|
||||
This weeks meeting is in {$meetingPlace}.
|
||||
```
|
||||
|
||||
|
||||
This above would output:
|
||||
|
||||
|
||||
Hello Doug Evans, glad to see you can make it.
|
||||
<br />
|
||||
This weeks meeting is in .
|
||||
This weeks meeting is in New York.
|
||||
|
||||
```html
|
||||
Hello Doug Evans, glad to see you can make it.
|
||||
<br />
|
||||
This weeks meeting is in .
|
||||
This weeks meeting is in New York.
|
||||
```
|
||||
|
||||
|
||||
Associative arrays {#language.variables.assoc.arrays}
|
||||
------------------
|
||||
## Associative arrays
|
||||
|
||||
You can also reference associative array variables by specifying the key
|
||||
after a dot \".\" symbol.
|
||||
after a dot "." symbol.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->assign('Contacts',
|
||||
array('fax' => '555-222-9876',
|
||||
'email' => 'zaphod@slartibartfast.example.com',
|
||||
'phone' => array('home' => '555-444-3333',
|
||||
'cell' => '555-111-1234')
|
||||
)
|
||||
);
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('Contacts',
|
||||
array('fax' => '555-222-9876',
|
||||
'email' => 'zaphod@slartibartfast.example.com',
|
||||
'phone' => array('home' => '555-444-3333',
|
||||
'cell' => '555-111-1234')
|
||||
)
|
||||
);
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
|
||||
{$Contacts.fax}<br />
|
||||
{$Contacts.email}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts.phone.home}<br />
|
||||
{$Contacts.phone.cell}<br />
|
||||
|
||||
|
||||
```smarty
|
||||
{$Contacts.fax}<br />
|
||||
{$Contacts.email}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts.phone.home}<br />
|
||||
{$Contacts.phone.cell}<br />
|
||||
```
|
||||
|
||||
this will output:
|
||||
|
||||
```html
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
```
|
||||
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
|
||||
|
||||
|
||||
Array indexes {#language.variables.array.indexes}
|
||||
-------------
|
||||
## Array indexes
|
||||
|
||||
You can reference arrays by their index, much like native PHP syntax.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->assign('Contacts', array(
|
||||
'555-222-9876',
|
||||
'zaphod@slartibartfast.example.com',
|
||||
array('555-444-3333',
|
||||
'555-111-1234')
|
||||
));
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('Contacts', array(
|
||||
'555-222-9876',
|
||||
'zaphod@slartibartfast.example.com',
|
||||
array('555-444-3333',
|
||||
'555-111-1234')
|
||||
));
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
|
||||
{$Contacts[0]}<br />
|
||||
{$Contacts[1]}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts[2][0]}<br />
|
||||
{$Contacts[2][1]}<br />
|
||||
|
||||
|
||||
```smarty
|
||||
{$Contacts[0]}<br />
|
||||
{$Contacts[1]}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts[2][0]}<br />
|
||||
{$Contacts[2][1]}<br />
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```html
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
```
|
||||
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
## Objects
|
||||
|
||||
|
||||
|
||||
Objects {#language.variables.objects}
|
||||
-------
|
||||
|
||||
Properties of [objects](#advanced.features.objects) assigned from PHP
|
||||
Properties of [objects](../../programmers/advanced-features/advanced-features-objects.md) assigned from PHP
|
||||
can be referenced by specifying the property name after the `->` symbol.
|
||||
|
||||
|
||||
name: {$person->name}<br />
|
||||
email: {$person->email}<br />
|
||||
|
||||
|
||||
```smarty
|
||||
name: {$person->name}<br />
|
||||
email: {$person->email}<br />
|
||||
```
|
||||
|
||||
this will output:
|
||||
|
||||
|
||||
name: Zaphod Beeblebrox<br />
|
||||
email: zaphod@slartibartfast.example.com<br />
|
||||
|
||||
|
||||
```html
|
||||
name: Zaphod Beeblebrox<br />
|
||||
email: zaphod@slartibartfast.example.com<br />
|
||||
```
|
@@ -1,83 +1,79 @@
|
||||
Variables loaded from config files {#language.config.variables}
|
||||
==================================
|
||||
# Variables loaded from config files
|
||||
|
||||
Variables that are loaded from the [config files](#config.files) are
|
||||
Variables that are loaded from the [config files](../config-files.md) are
|
||||
referenced by enclosing them within `#hash_marks#`, or with the smarty
|
||||
variable [`$smarty.config`](#language.variables.smarty.config). The
|
||||
variable [`$smarty.config`](language-variables-smarty.md#smartyconfig-languagevariablessmartyconfig). The
|
||||
later syntax is useful for embedding into quoted attribute values, or
|
||||
accessing variable values such as \$smarty.config.\$foo.
|
||||
accessing variable values such as `$smarty.config.$foo`.
|
||||
|
||||
## Examples
|
||||
|
||||
Example config file - `foo.conf`:
|
||||
|
||||
|
||||
pageTitle = "This is mine"
|
||||
bodyBgColor = '#eeeeee'
|
||||
tableBorderSize = 3
|
||||
tableBgColor = "#bbbbbb"
|
||||
rowBgColor = "#cccccc"
|
||||
|
||||
|
||||
```ini
|
||||
pageTitle = "This is mine"
|
||||
bodyBgColor = '#eeeeee'
|
||||
tableBorderSize = 3
|
||||
tableBgColor = "#bbbbbb"
|
||||
rowBgColor = "#cccccc"
|
||||
```
|
||||
|
||||
A template demonstrating the `#hash#` method:
|
||||
|
||||
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
```smarty
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
<title>{#pageTitle#}</title>
|
||||
<body bgcolor="{#bodyBgColor#}">
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
||||
```
|
||||
|
||||
|
||||
A template demonstrating the
|
||||
[`$smarty.config`](#language.variables.smarty.config) method:
|
||||
[`$smarty.config`](language-variables-smarty.md#smartyconfig-languagevariablessmartyconfig) method:
|
||||
|
||||
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
<title>{$smarty.config.pageTitle}</title>
|
||||
```smarty
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
<title>{$smarty.config.pageTitle}</title>
|
||||
<body bgcolor="{$smarty.config.bodyBgColor}">
|
||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
</html>
|
||||
```
|
||||
|
||||
Both examples would output:
|
||||
|
||||
|
||||
<html>
|
||||
```html
|
||||
<html>
|
||||
<title>This is mine</title>
|
||||
<body bgcolor="#eeeeee">
|
||||
<table border="3" bgcolor="#bbbbbb">
|
||||
<tr bgcolor="#cccccc">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="3" bgcolor="#bbbbbb">
|
||||
<tr bgcolor="#cccccc">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
</html>
|
||||
```
|
||||
|
||||
Config file variables cannot be used until after they are loaded in from
|
||||
a config file. This procedure is explained later in this document under
|
||||
[`{config_load}`](#language.function.config.load).
|
||||
[`{config_load}`](../language-builtin-functions/language-function-config-load.md).
|
||||
|
||||
See also [variables](#language.syntax.variables) and [\$smarty reserved
|
||||
variables](#language.variables.smarty)
|
||||
See also [variables](../language-basic-syntax/language-syntax-variables.md) and [$smarty reserved
|
||||
variables](language-variables-smarty.md).
|
||||
|
@@ -1,61 +1,60 @@
|
||||
Variable scopes {#language.variable.scopes}
|
||||
===============
|
||||
# Variable scopes
|
||||
|
||||
You have the choice to assign variables to the scope of the main Smarty
|
||||
object, data objects created with [`createData()`](#api.create.data),
|
||||
object, data objects created with [`createData()`](../../programmers/api-functions/api-create-data.md),
|
||||
and template objects created with
|
||||
[`createTemplate()`](#api.create.template). These objects can be
|
||||
[`createTemplate()`](../../programmers/api-functions/api-create-template.md). These objects can be
|
||||
chained. A template sees all the variables of its own object and all
|
||||
variables assigned to the objects in its chain of parent objects.
|
||||
|
||||
By default templates which are rendered by
|
||||
[`$smarty->display(...)`](#api.display) or
|
||||
[`$smarty->fetch(...)`](#api.fetch) calls are automatically linked to
|
||||
By default, templates which are rendered by
|
||||
[`$smarty->display(...)`](../../programmers/api-functions/api-display.md) or
|
||||
[`$smarty->fetch(...)`](../../programmers/api-functions/api-fetch.md) calls are automatically linked to
|
||||
the Smarty object variable scope.
|
||||
|
||||
By assigning variables to individual data or template objects you have
|
||||
full control which variables can be seen by a template.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// assign variable to Smarty object scope
|
||||
$smarty->assign('foo','smarty');
|
||||
|
||||
// assign variables to data object scope
|
||||
$data = $smarty->createData();
|
||||
$data->assign('foo','data');
|
||||
$data->assign('bar','bar-data');
|
||||
|
||||
// assign variable to Smarty object scope
|
||||
$smarty->assign('foo','smarty');
|
||||
// assign variables to other data object scope
|
||||
$data2 = $smarty->createData($data);
|
||||
$data2->assign('bar','bar-data2');
|
||||
|
||||
// assign variables to data object scope
|
||||
$data = $smarty->createData();
|
||||
$data->assign('foo','data');
|
||||
$data->assign('bar','bar-data');
|
||||
// assign variable to template object scope
|
||||
$tpl = $smarty->createTemplate('index.tpl');
|
||||
$tpl->assign('bar','bar-template');
|
||||
|
||||
// assign variables to other data object scope
|
||||
$data2 = $smarty->createData($data);
|
||||
$data2->assign('bar','bar-data2');
|
||||
// assign variable to template object scope with link to Smarty object
|
||||
$tpl2 = $smarty->createTemplate('index.tpl',$smarty);
|
||||
$tpl2->assign('bar','bar-template2');
|
||||
|
||||
// assign variable to template object scope
|
||||
$tpl = $smarty->createTemplate('index.tpl');
|
||||
$tpl->assign('bar','bar-template');
|
||||
// This display() does see $foo='smarty' from the $smarty object
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
// assign variable to template object scope with link to Smarty object
|
||||
$tpl2 = $smarty->createTemplate('index.tpl',$smarty);
|
||||
$tpl2->assign('bar','bar-template2');
|
||||
// This display() does see $foo='data' and $bar='bar-data' from the data object $data
|
||||
$smarty->display('index.tpl',$data);
|
||||
|
||||
// This display() does see $foo='smarty' from the $smarty object
|
||||
$smarty->display('index.tpl');
|
||||
// This display() does see $foo='data' from the data object $data
|
||||
// and $bar='bar-data2' from the data object $data2
|
||||
$smarty->display('index.tpl',$data2);
|
||||
|
||||
// This display() does see $foo='data' and $bar='bar-data' from the data object $data
|
||||
$smarty->display('index.tpl',$data);
|
||||
// This display() does see $bar='bar-template' from the template object $tpl
|
||||
$tpl->display(); // or $smarty->display($tpl);
|
||||
|
||||
// This display() does see $foo='data' from the data object $data
|
||||
// and $bar='bar-data2' from the data object $data2
|
||||
$smarty->display('index.tpl',$data2);
|
||||
// This display() does see $bar='bar-template2' from the template object $tpl2
|
||||
// and $foo='smarty' form the Smarty object $foo
|
||||
$tpl2->display(); // or $smarty->display($tpl2);
|
||||
```
|
||||
|
||||
// This display() does see $bar='bar-template' from the template object $tpl
|
||||
$tpl->display(); // or $smarty->display($tpl);
|
||||
|
||||
// This display() does see $bar='bar-template2' from the template object $tpl2
|
||||
// and $foo='smarty' form the Smarty object $foo
|
||||
$tpl2->display(); // or $smarty->display($tpl2);
|
||||
|
||||
|
||||
|
||||
See also [`assign()`](#api.assign), [`createData()`](#api.create.data)
|
||||
and [`createTemplate()`](#api.create.template).
|
||||
See also [`assign()`](../../programmers/api-functions/api-assign.md),
|
||||
[`createData()`](../../programmers/api-functions/api-create-data.md)
|
||||
and [`createTemplate()`](../../programmers/api-functions/api-create-template.md).
|
||||
|
@@ -1,43 +1,40 @@
|
||||
{\$smarty} reserved variable {#language.variables.smarty}
|
||||
============================
|
||||
# {$smarty} reserved variable
|
||||
|
||||
The PHP reserved `{$smarty}` variable can be used to access several
|
||||
environment and request variables. The full list of them follows.
|
||||
|
||||
Request variables {#language.variables.smarty.request}
|
||||
-----------------
|
||||
## Request variables
|
||||
|
||||
The [request variables](https://www.php.net/reserved.variables) such as
|
||||
`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, `$_ENV` and `$_SESSION` can
|
||||
be accessed as demonstrated in the examples below:
|
||||
|
||||
```smarty
|
||||
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
|
||||
{$smarty.get.page}
|
||||
|
||||
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
|
||||
{$smarty.get.page}
|
||||
{* display the variable "page" from a form ($_POST['page']) *}
|
||||
{$smarty.post.page}
|
||||
|
||||
{* display the variable "page" from a form ($_POST['page']) *}
|
||||
{$smarty.post.page}
|
||||
{* display the value of the cookie "username" ($_COOKIE['username']) *}
|
||||
{$smarty.cookies.username}
|
||||
|
||||
{* display the value of the cookie "username" ($_COOKIE['username']) *}
|
||||
{$smarty.cookies.username}
|
||||
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
|
||||
{$smarty.server.SERVER_NAME}
|
||||
|
||||
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
|
||||
{$smarty.server.SERVER_NAME}
|
||||
{* display the system environment variable "PATH" *}
|
||||
{$smarty.env.PATH}
|
||||
|
||||
{* display the system environment variable "PATH" *}
|
||||
{$smarty.env.PATH}
|
||||
{* display the php session variable "id" ($_SESSION['id']) *}
|
||||
{$smarty.session.id}
|
||||
|
||||
{* display the php session variable "id" ($_SESSION['id']) *}
|
||||
{$smarty.session.id}
|
||||
|
||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||
{$smarty.request.username}
|
||||
|
||||
|
||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||
{$smarty.request.username}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> For historical reasons `{$SCRIPT_NAME}` is short-hand for
|
||||
> For historical reasons `{$SCRIPT_NAME}` is shorthand for
|
||||
> `{$smarty.server.SCRIPT_NAME}`.
|
||||
>
|
||||
>
|
||||
@@ -51,46 +48,38 @@ be accessed as demonstrated in the examples below:
|
||||
> globals mixes underlying application code structure with templates. A
|
||||
> good practice is to assign specific needed values to template vars.
|
||||
|
||||
{\$smarty.now} {#language.variables.smarty.now}
|
||||
--------------
|
||||
## {$smarty.now}
|
||||
|
||||
The current [timestamp](https://www.php.net/function.time) can be accessed
|
||||
with `{$smarty.now}`. The value reflects the number of seconds passed
|
||||
since the so-called Epoch on January 1, 1970, and can be passed directly
|
||||
to the [`date_format`](#language.modifier.date.format) modifier for
|
||||
to the [`date_format`](../language-modifiers/language-modifier-date-format.md) modifier for
|
||||
display. Note that [`time()`](https://www.php.net/function.time) is called
|
||||
on each invocation; eg a script that takes three seconds to execute with
|
||||
a call to `$smarty.now` at start and end will show the three second
|
||||
a call to `$smarty.now` at start and end will show the three-second
|
||||
difference.
|
||||
|
||||
::: {.informalexample}
|
||||
```smarty
|
||||
{* use the date_format modifier to show current date and time *}
|
||||
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
|
||||
```
|
||||
|
||||
{* use the date_format modifier to show current date and time *}
|
||||
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
|
||||
|
||||
|
||||
:::
|
||||
|
||||
{\$smarty.const} {#language.variables.smarty.const}
|
||||
----------------
|
||||
## {$smarty.const}
|
||||
|
||||
You can access PHP constant values directly. See also [smarty
|
||||
constants](#smarty.constants).
|
||||
constants](../../programmers/smarty-constants.md).
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
<?php
|
||||
// the constant defined in php
|
||||
define('MY_CONST_VAL','CHERRIES');
|
||||
?>
|
||||
:::
|
||||
```php
|
||||
<?php
|
||||
// the constant defined in php
|
||||
define('MY_CONST_VAL','CHERRIES');
|
||||
```
|
||||
|
||||
Output the constant in a template with
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
{$smarty.const.MY_CONST_VAL}
|
||||
:::
|
||||
```smarty
|
||||
{$smarty.const.MY_CONST_VAL}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -99,78 +88,69 @@ Output the constant in a template with
|
||||
> application code structure into the templates. A good practice is to
|
||||
> assign specific needed values to template vars.
|
||||
|
||||
{\$smarty.capture} {#language.variables.smarty.capture}
|
||||
------------------
|
||||
## {$smarty.capture}
|
||||
|
||||
Template output captured via the built-in
|
||||
[`{capture}..{/capture}`](#language.function.capture) function can be
|
||||
[`{capture}..{/capture}`](../language-builtin-functions/language-function-capture.md) function can be
|
||||
accessed using the `{$smarty.capture}` variable. See the
|
||||
[`{capture}`](#language.function.capture) page for more information.
|
||||
[`{capture}`](../language-builtin-functions/language-function-capture.md) page for more information.
|
||||
|
||||
{\$smarty.config} {#language.variables.smarty.config}
|
||||
-----------------
|
||||
## {$smarty.config}
|
||||
|
||||
`{$smarty.config}` variable can be used to refer to loaded [config
|
||||
variables](#language.config.variables). `{$smarty.config.foo}` is a
|
||||
variables](language-config-variables.md). `{$smarty.config.foo}` is a
|
||||
synonym for `{#foo#}`. See the
|
||||
[{config\_load}](#language.function.config.load) page for more info.
|
||||
[{config_load}](../language-builtin-functions/language-function-config-load.md) page for more info.
|
||||
|
||||
{\$smarty.section} {#language.variables.smarty.loops}
|
||||
------------------
|
||||
## {$smarty.section}
|
||||
|
||||
The `{$smarty.section}` variables can be used to refer to
|
||||
[`{section}`](#language.function.section) loop properties. These have
|
||||
[`{section}`](../language-builtin-functions/language-function-section.md) loop properties. These have
|
||||
some very useful values such as `.first`, `.index`, etc.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The `{$smarty.foreach}` variable is no longer used with the new
|
||||
> [`{foreach}`](#language.function.foreach) syntax, but is still
|
||||
> [`{foreach}`](../language-builtin-functions/language-function-foreach.md) syntax, but is still
|
||||
> supported with Smarty 2.x style foreach syntax.
|
||||
|
||||
{\$smarty.template} {#language.variables.smarty.template}
|
||||
-------------------
|
||||
## {$smarty.template}
|
||||
|
||||
Returns the name of the current template being processed (without the
|
||||
directory).
|
||||
|
||||
{\$smarty.template\_object} {#language.variables.smarty.template_object}
|
||||
---------------------------
|
||||
## {$smarty.template_object}
|
||||
|
||||
Returns the template object of the current template being processed.
|
||||
|
||||
{\$smarty.current\_dir} {#language.variables.smarty.current_dir}
|
||||
-----------------------
|
||||
## {$smarty.current_dir}
|
||||
|
||||
Returns the name of the directory for the current template being
|
||||
processed.
|
||||
processed if it is loaded from the filesystem (the default).
|
||||
|
||||
{\$smarty.version} {#language.variables.smarty.version}
|
||||
------------------
|
||||
## {$smarty.version}
|
||||
|
||||
Returns the version of Smarty the template was compiled with.
|
||||
|
||||
```smarty
|
||||
<div id="footer">Powered by Smarty {$smarty.version}</div>
|
||||
```
|
||||
|
||||
<div id="footer">Powered by Smarty {$smarty.version}</div>
|
||||
|
||||
{\$smarty.block.child} {#language.variables.smarty.block.child}
|
||||
----------------------
|
||||
## {$smarty.block.child}
|
||||
|
||||
Returns block text from child template. See [Template
|
||||
inheritance](#advanced.features.template.inheritance).
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md).
|
||||
|
||||
{\$smarty.block.parent} {#language.variables.smarty.block.parent}
|
||||
-----------------------
|
||||
## {$smarty.block.parent}
|
||||
|
||||
Returns block text from parent template. See [Template
|
||||
inheritance](#advanced.features.template.inheritance)
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md)
|
||||
|
||||
{\$smarty.ldelim}, {\$smarty.rdelim} {#language.variables.smarty.ldelim}
|
||||
------------------------------------
|
||||
## {$smarty.ldelim}, {$smarty.rdelim}
|
||||
|
||||
These variables are used for printing the left-delimiter and
|
||||
right-delimiter value literally, the same as
|
||||
[`{ldelim},{rdelim}`](#language.function.ldelim).
|
||||
[`{ldelim},{rdelim}`](../language-builtin-functions/language-function-ldelim.md).
|
||||
|
||||
See also [assigned variables](#language.assigned.variables) and [config
|
||||
variables](#language.config.variables)
|
||||
See also [assigned variables](language-assigned-variables.md) and [config
|
||||
variables](language-config-variables.md)
|
||||
|
@@ -26,12 +26,12 @@ and 480 for $height, the result is:
|
||||
- [Getting Started](./getting-started.md)
|
||||
|
||||
## Smarty for template designers
|
||||
- [Basic Syntax](designers/language-basic-syntax/language-basic-syntax.md)
|
||||
- [Variables](./designers/language-variables.md)
|
||||
- [Variable Modifiers](./designers/language-modifiers.md)
|
||||
- [Basic Syntax](designers/language-basic-syntax/index.md)
|
||||
- [Variables](designers/language-variables/index.md)
|
||||
- [Variable Modifiers](designers/language-modifiers/index.md)
|
||||
- [Combining Modifiers](./designers/language-combining-modifiers.md)
|
||||
- [Built-in Functions](designers/language-builtin-functions/language-builtin-functions.md)
|
||||
- [Custom Functions](./designers/language-custom-functions.md)
|
||||
- [Built-in Functions](designers/language-builtin-functions/index.md)
|
||||
- [Custom Functions](designers/language-custom-functions/index.md)
|
||||
- [Config Files](./designers/config-files.md)
|
||||
- [Debugging Console](./designers/chapter-debugging-console.md)
|
||||
|
||||
|
@@ -14,4 +14,4 @@ auto\_literal to false.
|
||||
|
||||
:::
|
||||
|
||||
See also [Escaping Smarty Parsing](#language.escaping),
|
||||
See also [Escaping Smarty parsing](#language.escaping),
|
||||
|
54
mkdocs.yml
54
mkdocs.yml
@@ -36,9 +36,39 @@ nav:
|
||||
- Attributes: 'designers/language-basic-syntax/language-syntax-attributes.md'
|
||||
- Quotes: 'designers/language-basic-syntax/language-syntax-quotes.md'
|
||||
- Math: 'designers/language-basic-syntax/language-math.md'
|
||||
- 'Escaping Smarty Parsing': 'designers/language-basic-syntax/language-escaping.md'
|
||||
- 'designers/language-variables.md'
|
||||
- 'designers/language-modifiers.md'
|
||||
- 'Escaping Smarty parsing': 'designers/language-basic-syntax/language-escaping.md'
|
||||
- 'Variables':
|
||||
- 'Introduction': 'designers/language-variables/index.md'
|
||||
- 'Assigned from PHP': 'designers/language-variables/language-assigned-variables.md'
|
||||
- 'Variable scopes': 'designers/language-variables/language-variable-scopes.md'
|
||||
- 'From config files': 'designers/language-variables/language-config-variables.md'
|
||||
- '{$smarty}': 'designers/language-variables/language-variables-smarty.md'
|
||||
- 'Modifiers':
|
||||
- 'Introduction': 'designers/language-modifiers/index.md'
|
||||
- 'capitalize': 'designers/language-modifiers/language-modifier-capitalize.md'
|
||||
- 'cat': 'designers/language-modifiers/language-modifier-cat.md'
|
||||
- 'count_characters': 'designers/language-modifiers/language-modifier-count-characters.md'
|
||||
- 'count_paragraphs': 'designers/language-modifiers/language-modifier-count-paragraphs.md'
|
||||
- 'count_sentences': 'designers/language-modifiers/language-modifier-count-sentences.md'
|
||||
- 'count_words': 'designers/language-modifiers/language-modifier-count-words.md'
|
||||
- 'date_format': 'designers/language-modifiers/language-modifier-date-format.md'
|
||||
- 'default': 'designers/language-modifiers/language-modifier-default.md'
|
||||
- 'escape': 'designers/language-modifiers/language-modifier-escape.md'
|
||||
- 'from_charset': 'designers/language-modifiers/language-modifier-from-charset.md'
|
||||
- 'indent': 'designers/language-modifiers/language-modifier-indent.md'
|
||||
- 'lower': 'designers/language-modifiers/language-modifier-lower.md'
|
||||
- 'nl2br': 'designers/language-modifiers/language-modifier-nl2br.md'
|
||||
- 'regex_replace': 'designers/language-modifiers/language-modifier-regex-replace.md'
|
||||
- 'replace': 'designers/language-modifiers/language-modifier-replace.md'
|
||||
- 'spacify': 'designers/language-modifiers/language-modifier-spacify.md'
|
||||
- 'string_format': 'designers/language-modifiers/language-modifier-string-format.md'
|
||||
- 'strip': 'designers/language-modifiers/language-modifier-strip.md'
|
||||
- 'strip_tags': 'designers/language-modifiers/language-modifier-strip-tags.md'
|
||||
- 'to_charset': 'designers/language-modifiers/language-modifier-to-charset.md'
|
||||
- 'truncate': 'designers/language-modifiers/language-modifier-truncate.md'
|
||||
- 'unescape': 'designers/language-modifiers/language-modifier-unescape.md'
|
||||
- 'upper': 'designers/language-modifiers/language-modifier-upper.md'
|
||||
- 'wordwrap': 'designers/language-modifiers/language-modifier-wordwrap.md'
|
||||
- 'designers/language-combining-modifiers.md'
|
||||
- 'Builtin Functions':
|
||||
- 'Introduction': 'designers/language-builtin-functions/index.md'
|
||||
@@ -63,7 +93,23 @@ nav:
|
||||
- '{setfilter}': 'designers/language-builtin-functions/language-function-setfilter.md'
|
||||
- '{strip}': 'designers/language-builtin-functions/language-function-strip.md'
|
||||
- '{while}': 'designers/language-builtin-functions/language-function-while.md'
|
||||
- 'designers/language-custom-functions.md'
|
||||
- 'Custom Functions':
|
||||
- 'Introduction': 'designers/language-custom-functions/index.md'
|
||||
- '{counter}': 'designers/language-custom-functions/language-function-counter.md'
|
||||
- '{cycle}': 'designers/language-custom-functions/language-function-cycle.md'
|
||||
- '{debug}': 'designers/language-custom-functions/language-function-debug.md'
|
||||
- '{eval}': 'designers/language-custom-functions/language-function-eval.md'
|
||||
- '{fetch}': 'designers/language-custom-functions/language-function-fetch.md'
|
||||
- '{html_checkboxes}': 'designers/language-custom-functions/language-function-html-checkboxes.md'
|
||||
- '{html_image}': 'designers/language-custom-functions/language-function-html-image.md'
|
||||
- '{html_options}': 'designers/language-custom-functions/language-function-html-options.md'
|
||||
- '{html_radios}': 'designers/language-custom-functions/language-function-html-radios.md'
|
||||
- '{html_select_date}': 'designers/language-custom-functions/language-function-html-select-date.md'
|
||||
- '{html_select_time}': 'designers/language-custom-functions/language-function-html-select-time.md'
|
||||
- '{html_table}': 'designers/language-custom-functions/language-function-html-table.md'
|
||||
- '{mailto}': 'designers/language-custom-functions/language-function-mailto.md'
|
||||
- '{math}': 'designers/language-custom-functions/language-function-math.md'
|
||||
- '{textformat}': 'designers/language-custom-functions/language-function-textformat.md'
|
||||
- 'designers/config-files.md'
|
||||
- 'designers/chapter-debugging-console.md'
|
||||
- 'Programmers':
|
||||
|
Reference in New Issue
Block a user