> Smarty模板引擎中文在线手册 > 5. 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).
变量调节器用于变量,自定义函数和字符串。 请使用‘|’符号和调节器名称应用调节器。 变量调节器由赋予的参数值决定其行为。 参数由‘:’符号分开。

$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.

capitalize

This is used to capitalize the first letter of all words in a variable.
将变量里的所有单词首字大写。

Example 5-2. capitalize
例 5-2.首字大写

index.php:

$smarty = new Smarty;
$smarty->assign('articleTitle', 'Police begin campaign to rundown jaywalkers.');
$smarty->display('index.tpl');

index.tpl:

{$articleTitle}
{$articleTitle|capitalize}

OUTPUT:

Police begin campaign to rundown jaywalkers.
Police Begin Campaign To Rundown Jaywalkers.