capitalize
cat
count_characters
count_paragraphs
count_sentences
count_words
date_format
default
escape
indent
lower
nl2br
regex_replace
replace
spacify
string_format
strip
strip_tags
truncate
upper
wordwrap
变量调节器作用于变量、自定义函数或字符串。变量调节器的用法是:‘|’符号右接调节器名称。变量调节器可接收附加参数影响其行为。参数位于调节器右边,并用‘:’符号分开。
例 5-1.调节器的例子
{* 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 *}
{* php函数作为调节器 *} {"="|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>
|
调节器可以应用于任何类型变量,包括数组和对象;
Smarty3更改了调节器默认行为。在2.x版本,数组必须使用‘@’符号应用调节器,例如{$articleTitle|@count},但在3.X,‘@’不是必须的,默认将其忽略掉。
如果你想将调节器作用于数组的每一项,有两种做法可选,一是必须在模板中循环数组;二是在你的调节器函数中提供循环功能。