Dev-Umgebung: Kompatibilität für PHP 8.3 + Smarty 4.5.6
- Smarty 4.1.1 → 4.5.6 (behebt dynamic property deprecations) - Core-Klassen: #[\AllowDynamicProperties] für Admin_role, base, Config, Customer, Customer_group, CustomerGroups, Item, Structure, website - website.class.php: counts[parent_id] initialisieren vor ++ (PHP 8.1) - layout.class.php: HTTP_ACCEPT_LANGUAGE mit isset-Guard - website_init.php: session_status()-Check vor session_start - .htaccess: HTTPS-Redirect via X-Forwarded-Proto (statt SERVER_PORT) - themes/easyshop_advanced/media/: Parent-Theme-Assets nachgezogen - .gitignore: smarty.4.1.1.bak ausschließen
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
# Variable Modifiers
|
||||
|
||||
Variable modifiers can be applied to
|
||||
[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).
|
||||
|
||||
- [capitalize](language-modifier-capitalize.md)
|
||||
- [cat](language-modifier-cat.md)
|
||||
- [count](language-modifier-count.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)
|
||||
- [debug_print_var](language-modifier-debug-print-var.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
|
||||
|
||||
```smarty
|
||||
{* apply modifier to a variable *}
|
||||
{$title|upper}
|
||||
|
||||
{* modifier with parameters *}
|
||||
{$title|truncate:40:"..."}
|
||||
|
||||
{* apply modifier to a function parameter *}
|
||||
{html_table loop=$myvar|upper}
|
||||
|
||||
{* with parameters *}
|
||||
{html_table loop=$myvar|truncate:40:"..."}
|
||||
|
||||
{* apply modifier to literal string *}
|
||||
{"foobar"|upper}
|
||||
|
||||
{* using date_format to format the current date *}
|
||||
{$smarty.now|date_format:"%Y/%m/%d"}
|
||||
|
||||
{* apply modifier to a custom function *}
|
||||
{mailto|upper address="smarty@example.com"}
|
||||
|
||||
{* using php's str_repeat *}
|
||||
{"="|str_repeat:80}
|
||||
|
||||
{* php's count *}
|
||||
{$myArray|@count}
|
||||
|
||||
{* this will uppercase and truncate the whole array *}
|
||||
<select name="name_id">
|
||||
{html_options output=$my_array|upper|truncate:20}
|
||||
</select>
|
||||
```
|
||||
|
||||
- Modifiers can be applied to any type of variables, including arrays
|
||||
and objects.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The default behavior was changed with Smarty 3. In Smarty 2.x, you
|
||||
> had to use an "`@`" symbol to apply a modifier to an array, such
|
||||
> as `{$articleTitle|@count}`. With Smarty 3, the "`@`" is no
|
||||
> longer necessary, and is ignored.
|
||||
>
|
||||
> If you want a modifier to apply to each individual item of an
|
||||
> array, you will either need to loop the array in the template, or
|
||||
> provide for this functionality inside your modifier function.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Second, in Smarty 2.x, modifiers were applied to the result of
|
||||
> math expressions like `{8+2}`, meaning that
|
||||
> `{8+2|count_characters}` would give `2`, as 8+2=10 and 10 is two
|
||||
> characters long. With Smarty 3, modifiers are applied to the
|
||||
> variables or atomic expressions before executing the calculations,
|
||||
> so since 2 is one character long, `{8+2|count_characters}`
|
||||
> gives 9. To get the old result use parentheses like
|
||||
> `{(8+2)|count_characters}`.
|
||||
|
||||
- Modifiers are autoloaded from the
|
||||
[`$plugins_dir`](../../programmers/api-variables/variable-plugins-dir.md) or can be registered
|
||||
explicitly with the [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md)
|
||||
function. The later is useful for sharing a function between php
|
||||
scripts and smarty templates.
|
||||
|
||||
- All php-functions can be used as modifiers implicitly, as
|
||||
demonstrated in the example above. However, using php-functions as
|
||||
modifiers has two little pitfalls:
|
||||
|
||||
- First - sometimes the order of the function-parameters is not
|
||||
the desirable one. Formatting `$foo` with
|
||||
`{"%2.f"|sprintf:$foo}` actually works, but asks for the more
|
||||
intuitive, like `{$foo|string_format:"%2.f"}` that is provided
|
||||
by the Smarty distribution.
|
||||
|
||||
- Secondly - if security is enabled, all php-functions that are to
|
||||
be used as modifiers have to be declared trusted in the
|
||||
`$modifiers` property of the security policy. See the
|
||||
[Security](../../programmers/advanced-features/advanced-features-security.md) section for details.
|
||||
|
||||
See also [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md), [combining
|
||||
modifiers](../language-combining-modifiers.md). and [extending smarty with
|
||||
plugins](../../programmers/plugins.md)
|
||||
@@ -0,0 +1,49 @@
|
||||
# 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.
|
||||
|
||||
## 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" |
|
||||
|
||||
|
||||
## 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.md) and
|
||||
[`upper`](language-modifier-upper.md)
|
||||
@@ -0,0 +1,36 @@
|
||||
# cat
|
||||
|
||||
This value is concatenated to the given variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|cat:' units'}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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.
|
||||
```
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# count_characters
|
||||
|
||||
This is used to count the number of characters in a variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_characters}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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.md),
|
||||
[`count_sentences`](language-modifier-count-sentences.md) and
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md).
|
||||
@@ -0,0 +1,41 @@
|
||||
# count_paragraphs
|
||||
|
||||
This is used to count the number of paragraphs in a variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_paragraphs}
|
||||
```
|
||||
|
||||
## 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.md),
|
||||
[`count_sentences`](language-modifier-count-sentences.md) and
|
||||
[`count_words`](language-modifier-count-words.md).
|
||||
@@ -0,0 +1,39 @@
|
||||
# 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}
|
||||
```
|
||||
|
||||
## 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.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_words`](language-modifier-count-words.md).
|
||||
@@ -0,0 +1,35 @@
|
||||
# count_words
|
||||
|
||||
This is used to count the number of words in a variable.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|count_words}
|
||||
```
|
||||
|
||||
## 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.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_sentences`](language-modifier-count-sentences.md).
|
||||
@@ -0,0 +1,21 @@
|
||||
# count
|
||||
|
||||
Returns the number of elements in an array (or Countable object). Will return 0 for null.
|
||||
Returns 1 for any other type (such as a string).
|
||||
|
||||
If the optional mode parameter is set to 1, count() will recursively count the array.
|
||||
This is particularly useful for counting all the elements of a multidimensional array.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{if $myVar|count > 3}4 or more{/if}
|
||||
{if count($myVar) > 3}4 or more{/if}
|
||||
```
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|--------------------------------------------------------|
|
||||
| 1 | int | No | If set to 1, count() will recursively count the array. |
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
# date_format
|
||||
|
||||
This formats a date and time into the given
|
||||
[`strftime()`](https://www.php.net/strftime) format. Dates can be passed to
|
||||
Smarty as unix [timestamps](https://www.php.net/function.time), [DateTime
|
||||
objects](https://www.php.net/class.DateTime), mysql timestamps or any string
|
||||
made up of month day year, parsable by php\'s
|
||||
[`strtotime()`](https://www.php.net/strtotime). Designers can then use
|
||||
`date_format` to have complete control of the formatting of the date. If
|
||||
the date passed to `date_format` is empty and a second parameter is
|
||||
passed, that will be used as the date to format.
|
||||
|
||||
## 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**
|
||||
>
|
||||
> Since Smarty-2.6.10 numeric values passed to `date_format` are
|
||||
> *always* (except for mysql timestamps, see below) interpreted as a
|
||||
> unix timestamp.
|
||||
>
|
||||
> Before Smarty-2.6.10 numeric strings that where also parsable by
|
||||
> `strtotime()` in php (like `YYYYMMDD`) where sometimes (depending on
|
||||
> the underlying implementation of `strtotime()`) interpreted as date
|
||||
> strings and NOT as timestamps.
|
||||
>
|
||||
> The only exception are mysql timestamps: They are also numeric only
|
||||
> and 14 characters long (`YYYYMMDDHHMMSS`), mysql timestamps have
|
||||
> precedence over unix timestamps.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> `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
|
||||
> [`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
|
||||
|
||||
$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/language-variables-smarty.md#smartynow-languagevariablessmartynow) to
|
||||
get the current 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
|
||||
```
|
||||
|
||||
## 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
|
||||
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
|
||||
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
|
||||
to 23)
|
||||
- %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.
|
||||
(range 0 to 23)
|
||||
- %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
|
||||
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
|
||||
Monday
|
||||
- %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
|
||||
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
|
||||
with the first Monday as the first day of the first week
|
||||
- %x - preferred date representation for the current locale without
|
||||
the time
|
||||
- %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
|
||||
|
||||
See also [`$smarty.now`](../language-variables/language-variables-smarty.md#smartynow-languagevariablessmartynow),
|
||||
[`strftime()`](https://www.php.net/strftime),
|
||||
[`{html_select_date}`](../language-custom-functions/language-function-html-select-date.md) and the
|
||||
[date tips](../../appendixes/tips.md#dates) page.
|
||||
@@ -0,0 +1,26 @@
|
||||
# debug_print_var
|
||||
|
||||
|
||||
|
||||
Returns the value of the given variable in a human-readable format in HTML.
|
||||
Used in the [debug console](../chapter-debugging-console.md), but you can also use it in your template
|
||||
while developing to see what is going on under the hood.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Use for debugging only! Since you may accidentally reveal sensitive information or introduce vulnerabilities such as XSS using this
|
||||
method never use it in production.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|debug_print_var}
|
||||
```
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|------------------------------------------------------------------------|
|
||||
| 1 | int | No | maximum recursion depth if $var is an array or object (defaults to 10) |
|
||||
| 2 | int | No | maximum string length if $var is a string (defaults to 40) |
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# 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.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|default:"(none)"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
See also the [default variable handling](../../appendixes/tips.md#default-variable-handling) and
|
||||
the [blank variable handling](../../appendixes/tips.md#blank-variable-handling) pages.
|
||||
@@ -0,0 +1,78 @@
|
||||
# escape
|
||||
|
||||
`escape` is used to encode or escape a variable to `html`, `url`,
|
||||
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
|
||||
its `html`.
|
||||
|
||||
## 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) |
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```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|escape}
|
||||
'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'
|
||||
|
||||
<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\'
|
||||
|
||||
<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
|
||||
|
||||
{* the "rewind" parameter registers the current location *}
|
||||
<a href="$my_path?page=foo&rewind={$my_uri|escape:url}">click here</a>
|
||||
|
||||
```
|
||||
|
||||
This snippet is useful for emails, but see also
|
||||
[`{mailto}`](../language-custom-functions/language-function-mailto.md)
|
||||
|
||||
```smarty
|
||||
{* email address mangled *}
|
||||
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
|
||||
```
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,20 @@
|
||||
# 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.md).
|
||||
|
||||
## 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**
|
||||
>
|
||||
> Charset encoding should be handled by the application itself. This
|
||||
> 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](../../programmers/charset.md), [to_charset
|
||||
modifier](language-modifier-to-charset.md).
|
||||
@@ -0,0 +1,67 @@
|
||||
# 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. For example: use `"\t"` for a tab.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|indent:4}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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. |
|
||||
|
||||
## 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|indent}
|
||||
|
||||
{$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.
|
||||
```
|
||||
|
||||
|
||||
See also [`strip`](language-modifier-strip.md),
|
||||
[`wordwrap`](language-modifier-wordwrap.md) and
|
||||
[`spacify`](language-modifier-spacify.md).
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```smarty
|
||||
{$articleTitle}
|
||||
{$articleTitle|lower}
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```
|
||||
Two Convicts Evade Noose, Jury Hung.
|
||||
two convicts evade noose, jury hung.
|
||||
```
|
||||
|
||||
See also [`upper`](language-modifier-upper.md) and
|
||||
[`capitalize`](language-modifier-capitalize.md).
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Sun or rain expected\ntoday, dark tonight"
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Where the template is:
|
||||
|
||||
```smarty
|
||||
{$articleTitle|nl2br}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Sun or rain expected<br />today, dark tonight
|
||||
```
|
||||
|
||||
See also [`word_wrap`](language-modifier-wordwrap.md),
|
||||
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
||||
[`count_sentences`](language-modifier-count-sentences.md).
|
||||
@@ -0,0 +1,55 @@
|
||||
# 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
|
||||
> usually better to apply regular expressions in PHP, either via custom
|
||||
> functions or modifiers. Regular expressions are considered application
|
||||
> code and are not part of presentation logic.
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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. |
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```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 *}
|
||||
|
||||
{$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.
|
||||
```
|
||||
|
||||
|
||||
See also [`replace`](language-modifier-replace.md) and
|
||||
[`escape`](language-modifier-escape.md).
|
||||
@@ -0,0 +1,45 @@
|
||||
# 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.
|
||||
|
||||
## 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. |
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```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.
|
||||
```
|
||||
|
||||
See also [`regex_replace`](language-modifier-regex-replace.md) and
|
||||
[`escape`](language-modifier-escape.md).
|
||||
@@ -0,0 +1,44 @@
|
||||
# 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.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|spacify}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|--------|----------|-------------|-----------------------------------------------------------------|
|
||||
| 1 | string | No | *one space* | This what gets inserted between each character of the variable. |
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```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^^.
|
||||
```
|
||||
|
||||
See also [`wordwrap`](language-modifier-wordwrap.md) and
|
||||
[`nl2br`](language-modifier-nl2br.md).
|
||||
@@ -0,0 +1,43 @@
|
||||
# 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.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|string_format:"%d"}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Description |
|
||||
|--------------------|--------|----------|---------------------------------------|
|
||||
| 1 | string | Yes | This is what format to use. (sprintf) |
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->assign('number', 23.5787446);
|
||||
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```smarty
|
||||
{$number}
|
||||
{$number|string_format:"%.2f"}
|
||||
{$number|string_format:"%d"}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
23.5787446
|
||||
23.58
|
||||
23
|
||||
```
|
||||
|
||||
See also [`date_format`](language-modifier-date-format.md).
|
||||
@@ -0,0 +1,46 @@
|
||||
# strip_tags
|
||||
|
||||
This strips out HTML markup tags, basically anything between `<` and `>`.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|strip_tags}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter Position | Type | Required | Default | Description |
|
||||
|--------------------|------|----------|---------|------------------------------------------------------------|
|
||||
| 1 | bool | No | TRUE | This determines whether the tags are replaced by ' ' or '' |
|
||||
|
||||
## 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:
|
||||
|
||||
```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.
|
||||
```
|
||||
|
||||
See also [`replace`](language-modifier-replace.md) and
|
||||
[`regex_replace`](language-modifier-regex-replace.md).
|
||||
@@ -0,0 +1,42 @@
|
||||
# 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-builtin-functions/language-function-strip.md) function.
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```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.
|
||||
```
|
||||
|
||||
See also [`{strip}`](../language-builtin-functions/language-function-strip.md) and
|
||||
[`truncate`](language-modifier-truncate.md).
|
||||
@@ -0,0 +1,20 @@
|
||||
# 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
|
||||
modifier](#language.modifier.from_charset).
|
||||
|
||||
## 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**
|
||||
>
|
||||
> Charset encoding should be handled by the application itself. This
|
||||
> 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](../../programmers/charset.md), [from_charset
|
||||
modifier](language-modifier-from-charset.md).
|
||||
@@ -0,0 +1,57 @@
|
||||
# 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
|
||||
display at the end if the variable was truncated. The characters in the
|
||||
string are included with the original truncation length. By default,
|
||||
`truncate` will attempt to cut off at a word boundary. If you want to
|
||||
cut off at the exact character length, pass the optional third parameter
|
||||
of TRUE.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|truncate:40:"..."}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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:
|
||||
|
||||
```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.
|
||||
```
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# unescape
|
||||
|
||||
`unescape` is used to decode `entity`, `html` and `htmlall`. It counters
|
||||
the effects of the [escape modifier](language-modifier-escape.md) for the
|
||||
given types.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|unescape}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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. |
|
||||
|
||||
## 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|unescape:"html"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
|
||||
{$articleTitle|unescape:"htmlall"}
|
||||
Germans use "Ümlauts" and pay in €uro
|
||||
```
|
||||
|
||||
See also [escaping smarty parsing](../language-basic-syntax/language-escaping.md), [escape
|
||||
modifier](language-modifier-escape.md).
|
||||
@@ -0,0 +1,33 @@
|
||||
# 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}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||
```
|
||||
|
||||
Where template is:
|
||||
|
||||
```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.
|
||||
```
|
||||
|
||||
See also [`lower`](lower) and
|
||||
[`capitalize`](language-modifier-capitalize.md).
|
||||
@@ -0,0 +1,73 @@
|
||||
# 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
|
||||
the next line, the default is a carriage return `"\n"`. By default,
|
||||
`wordwrap` will attempt to wrap at a word boundary. If you want to cut
|
||||
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.
|
||||
|
||||
## Basic usage
|
||||
```smarty
|
||||
{$myVar|wordwrap:30}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| 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). |
|
||||
|
||||
## 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|wordwrap:30}
|
||||
|
||||
{$articleTitle|wordwrap:20}
|
||||
|
||||
{$articleTitle|wordwrap:30:"<br />\n"}
|
||||
|
||||
{$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<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.
|
||||
```
|
||||
|
||||
See also [`nl2br`](language-modifier-nl2br.md) and
|
||||
[`{textformat}`](../language-custom-functions/language-function-textformat.md).
|
||||
Reference in New Issue
Block a user