Upgrade from Smarty 3 to Smarty 4 to be PHP 8.1 compatible
Remove all Smarty4 dedicated tests, all are done in the same test file like before
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
capitalize {#language.modifier.capitalize}
|
||||
==========
|
||||
|
||||
This is used to capitalize the first letter of all words in a variable.
|
||||
This is similar to the PHP [`ucwords()`](&url.php-manual;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\"
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where the template is:
|
||||
|
||||
|
||||
{$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)
|
||||
@@ -0,0 +1,31 @@
|
||||
cat {#language.modifier.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.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Psychics predict world didn't end");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle|cat:' yesterday.'}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
Psychics predict world didn't end yesterday.
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
count\_characters {#language.modifier.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.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Cold Wave Linked to Temperatures.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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).
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
count\_paragraphs {#language.modifier.count.paragraphs}
|
||||
=================
|
||||
|
||||
This is used to count the number of paragraphs in a variable.
|
||||
|
||||
|
||||
<?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:
|
||||
|
||||
|
||||
{$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).
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
count\_sentences {#language.modifier.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 (.?!).
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
'Two Soviet Ships Collide - One Dies.
|
||||
Enraged Cow Injures Farmer with Axe.'
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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).
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
count\_words {#language.modifier.count.words}
|
||||
============
|
||||
|
||||
This is used to count the number of words in a variable.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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).
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
date\_format {#language.modifier.date.format}
|
||||
============
|
||||
|
||||
This formats a date and time into the given
|
||||
[`strftime()`](&url.php-manual;strftime) format. Dates can be passed to
|
||||
Smarty as unix [timestamps](&url.php-manual;function.time), [DateTime
|
||||
objects](&url.php-manual;class.DateTime), mysql timestamps or any string
|
||||
made up of month day year, parsable by php\'s
|
||||
[`strtotime()`](&url.php-manual;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.
|
||||
|
||||
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()`](&url.php-manual;strftime) function. You may have more
|
||||
> or less conversion specifiers available depending on your system\'s
|
||||
> [`strftime()`](&url.php-manual;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.
|
||||
|
||||
|
||||
<?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.smarty.now) 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}
|
||||
|
||||
|
||||
|
||||
This above will output:
|
||||
|
||||
|
||||
Jan 1, 2022
|
||||
01/01/22
|
||||
02:33 pm
|
||||
Dec 31, 2021
|
||||
Monday, December 1, 2021
|
||||
14:33:00
|
||||
|
||||
|
||||
|
||||
`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.smarty.now),
|
||||
[`strftime()`](&url.php-manual;strftime),
|
||||
[`{html_select_date}`](#language.function.html.select.date) and the
|
||||
[date tips](#tips.dates) page.
|
||||
@@ -0,0 +1,41 @@
|
||||
default {#language.modifier.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.
|
||||
|
||||
|
||||
<?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'}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,74 @@
|
||||
escape {#language.modifier.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()`](&url.php-manual;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)
|
||||
|
||||
|
||||
<?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
|
||||
|
||||
|
||||
{$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|urlencode}">click here</a>
|
||||
|
||||
|
||||
|
||||
This snippet is useful for emails, but see also
|
||||
[`{mailto}`](#language.function.mailto)
|
||||
|
||||
|
||||
{* 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.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
from\_charset {#language.modifier.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).
|
||||
|
||||
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()`](&url.php-manual;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 Enconding](#charset), [from\_charset
|
||||
modifier](#language.modifier.from_charset).
|
||||
@@ -0,0 +1,62 @@
|
||||
indent {#language.modifier.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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
<?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:
|
||||
|
||||
|
||||
{$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),
|
||||
[`wordwrap`](#language.modifier.wordwrap) and
|
||||
[`spacify`](#language.modifier.spacify).
|
||||
@@ -0,0 +1,33 @@
|
||||
lower {#language.modifier.lower}
|
||||
=====
|
||||
|
||||
This is used to lowercase a variable. This is equivalent to the PHP
|
||||
[`strtolower()`](&url.php-manual;strtolower) function.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|lower}
|
||||
|
||||
|
||||
|
||||
This will output:
|
||||
|
||||
|
||||
Two Convicts Evade Noose, Jury Hung.
|
||||
two convicts evade noose, jury hung.
|
||||
|
||||
|
||||
|
||||
See also [`upper`](#language.modifier.upper) and
|
||||
[`capitalize`](#language.modifier.capitalize).
|
||||
@@ -0,0 +1,35 @@
|
||||
nl2br {#language.modifier.nl2br}
|
||||
=====
|
||||
|
||||
All `"\n"` line breaks will be converted to html `<br />` tags in the
|
||||
given variable. This is equivalent to the PHP\'s
|
||||
[`nl2br()`](&url.php-manual;nl2br) function.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Sun or rain expected\ntoday, dark tonight"
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where the template is:
|
||||
|
||||
|
||||
{$articleTitle|nl2br}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
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).
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
regex\_replace {#language.modifier.regex.replace}
|
||||
==============
|
||||
|
||||
A regular expression search and replace on a variable. Use the
|
||||
[`preg_replace()`](&url.php-manual;preg_replace) syntax from the PHP
|
||||
manual.
|
||||
|
||||
> **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 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.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{* 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) and
|
||||
[`escape`](#language.modifier.escape).
|
||||
@@ -0,0 +1,40 @@
|
||||
replace {#language.modifier.replace}
|
||||
=======
|
||||
|
||||
A simple search and replace on a variable. This is equivalent to the
|
||||
PHP\'s [`str_replace()`](&url.php-manual;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.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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) and
|
||||
[`escape`](#language.modifier.escape).
|
||||
@@ -0,0 +1,40 @@
|
||||
spacify {#language.modifier.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.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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) and
|
||||
[`nl2br`](#language.modifier.nl2br).
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
string\_format {#language.modifier.string.format}
|
||||
==============
|
||||
|
||||
This is a way to format strings, such as decimal numbers and such. Use
|
||||
the syntax for [`sprintf()`](&url.php-manual;sprintf) for the
|
||||
formatting.
|
||||
|
||||
Parameter Position Type Required Default Description
|
||||
-------------------- -------- ---------- --------- ---------------------------------------
|
||||
1 string Yes *n/a* This is what format to use. (sprintf)
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('number', 23.5787446);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$number}
|
||||
{$number|string_format:"%.2f"}
|
||||
{$number|string_format:"%d"}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
23.5787446
|
||||
23.58
|
||||
23
|
||||
|
||||
|
||||
|
||||
See also [`date_format`](#language.modifier.date.format).
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
strip\_tags {#language.modifier.strip.tags}
|
||||
===========
|
||||
|
||||
This strips out 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 \'\'
|
||||
|
||||
|
||||
<?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}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
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).
|
||||
@@ -0,0 +1,40 @@
|
||||
strip {#language.modifier.strip}
|
||||
=====
|
||||
|
||||
This replaces all spaces, newlines and tabs with a single space, or with
|
||||
the supplied string.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If you want to strip blocks of template text, use the built-in
|
||||
> [`{strip}`](#language.function.strip) function.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip}
|
||||
{$articleTitle|strip:' '}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
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).
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
to\_charset {#language.modifier.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).
|
||||
|
||||
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()`](&url.php-manual;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 Enconding](#charset), [from\_charset
|
||||
modifier](#language.modifier.from_charset).
|
||||
@@ -0,0 +1,52 @@
|
||||
truncate {#language.modifier.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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
<?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}
|
||||
|
||||
|
||||
|
||||
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,39 @@
|
||||
unescape {#language.modifier.unescape}
|
||||
========
|
||||
|
||||
`unescape` is used to decode `entity`, `html` and `htmlall`. It counters
|
||||
the effects of the [escape modifier](#language.modifier.escape) 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()`](&url.php-manual;htmlentities) `UTF-8` The character set encoding passed to html\_entity\_decode() or htmlspecialchars\_decode() or mb\_convert\_encoding() et. al.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Germans use "Ümlauts" and pay in €uro"
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
These are example `unescape` template lines followed by the output
|
||||
|
||||
|
||||
{$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.escaping), [escape
|
||||
modifier](#language.modifier.escape).
|
||||
@@ -0,0 +1,31 @@
|
||||
upper {#language.modifier.upper}
|
||||
=====
|
||||
|
||||
This is used to uppercase a variable. This is equivalent to the PHP
|
||||
[`strtoupper()`](&url.php-manual;strtoupper) function.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is:
|
||||
|
||||
|
||||
{$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`](#language.modifier.lower) and
|
||||
[`capitalize`](#language.modifier.capitalize).
|
||||
@@ -0,0 +1,69 @@
|
||||
wordwrap {#language.modifier.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()`](&url.php-manual;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).
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->assign('articleTitle',
|
||||
"Blind woman gets new kidney from dad she hasn't seen in years."
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where template is
|
||||
|
||||
|
||||
{$articleTitle}
|
||||
|
||||
{$articleTitle|wordwrap:30}
|
||||
|
||||
{$articleTitle|wordwrap:20}
|
||||
|
||||
{$articleTitle|wordwrap:30:"<br />\n"}
|
||||
|
||||
{$articleTitle|wordwrap:26:"\n":true}
|
||||
|
||||
|
||||
|
||||
Will output:
|
||||
|
||||
|
||||
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) and
|
||||
[`{textformat}`](#language.function.textformat).
|
||||
Reference in New Issue
Block a user