?
This document uses PHP Chinese website manual Release
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).
變量調(diào)節(jié)器用于變量,自定義函數(shù)和字符串。
請(qǐng)使用‘|’符號(hào)和調(diào)節(jié)器名稱(chēng)應(yīng)用調(diào)節(jié)器。
變量調(diào)節(jié)器由賦予的參數(shù)值決定其行為。
參數(shù)由‘:’符號(hào)分開(kāi)。
Example 5-1. modifier example
|
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.)
如果你給數(shù)組變量應(yīng)用單值變量的調(diào)節(jié),結(jié)果是數(shù)組的每個(gè)值都被調(diào)節(jié)。
如果你只想要調(diào)節(jié)器用一個(gè)值調(diào)節(jié)整個(gè)數(shù)組,你必須在調(diào)節(jié)器名字前加上@符號(hào)。
例如: {$articleTitle|@count}(這將會(huì)在 $articleTitle 數(shù)組里輸出元素的數(shù)目)
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 implicitely. (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.
This is used to capitalize the first letter of all words in a variable.
將變量里的所有單詞首字大寫(xiě)。
Example 5-2. capitalize
|