Variable Modifiers
Variable modifiers can be applied to variables, custom functions or strings. To
apply a modifier, specify the value followed by the |
(pipe) and the modifier name. A modifier may accept additional parameters
that affect its behavior. These parameters follow the modifer name and are
separated by : (colon).
modifier example
{$title|upper}
{* Truncate the topic to 40 characters use ... at the end *}
Topic: {$topic|truncate:40:"..."}
{* format a literal string *}
{"now"|date_format:"%Y/%m/%d"}
{* apply modifier to a custom function *}
{mailto|upper address="me@domain.dom"}
]]>
If you apply a modifier to an array variable instead of a single value variable,
the modifier will be applied to every value in that array. If you really want
the modifier to work on an entire array as a value, you must prepend the
modifier name with an @ symbol like so:
{$articleTitle|@count} (this will print out the number of
elements in the $articleTitle array.)
Modifiers can be autoloaded from your $plugins_dir (also see:
Naming
Conventions) or can be registered explicitely (see: register_modifier). Additionally
all php-functions can be used as modifiers implicitly. (The
@count-example above actually uses php's
count-function and not a smarty-modifier). Using php-functions
as modifiers has two little pitfalls: First: Sometimes the order
of the function-parameters is not the desirable one
({"%2.f"|sprintf:$float} actually works, but
asks for the more intuitive. For example:{$float|string_format:"%2.f"}
that is provided by the Smarty distribution). Second: with $security turned on all
php-functions that are to be used as modifiers have to be
declared trusted in the
$security_settings['MODIFIER_FUNCS']-array.
&designers.language-modifiers.language-modifier-capitalize;
&designers.language-modifiers.language-modifier-count-characters;
&designers.language-modifiers.language-modifier-cat;
&designers.language-modifiers.language-modifier-count-paragraphs;
&designers.language-modifiers.language-modifier-count-sentences;
&designers.language-modifiers.language-modifier-count-words;
&designers.language-modifiers.language-modifier-date-format;
&designers.language-modifiers.language-modifier-default;
&designers.language-modifiers.language-modifier-escape;
&designers.language-modifiers.language-modifier-indent;
&designers.language-modifiers.language-modifier-lower;
&designers.language-modifiers.language-modifier-nl2br;
&designers.language-modifiers.language-modifier-regex-replace;
&designers.language-modifiers.language-modifier-replace;
&designers.language-modifiers.language-modifier-spacify;
&designers.language-modifiers.language-modifier-string-format;
&designers.language-modifiers.language-modifier-strip;
&designers.language-modifiers.language-modifier-strip-tags;
&designers.language-modifiers.language-modifier-truncate;
&designers.language-modifiers.language-modifier-upper;
&designers.language-modifiers.language-modifier-wordwrap;