Chapter 5. Variable Modifiers[����������]

Table of Contents
capitalize[���ִ�д]
count_characters[�ַ�����]
cat[�����ַ���]
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

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

�������������ڱ���,�Զ��庯�����ַ���.
��ʹ��'|'���ź͵���������Ӧ�õ�����.
�����������ɸ���IJ���ֵ��������Ϊ.
������':'���ŷֿ�.

Example 5-1. modifier example
�� 5-1.������������

{* ����һ��percase the title *}
{* �����д *} <h2>{$title|upper}</h2> {* Truncate the topic to 40 characters use ... at the end *} {* ȡ��ǰ40���ַ� *} Topic: {$topic|truncate:40:"..."} {* format a literal string *} {* ��ʽ�����ִ� *} {"now"|date_format:"%Y/%m/%d"} {* apply modifier to a custom function *} {* ���Զ��庯����Ӧ�õ����� *} {mailto|upper address="[email protected]"}

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

�������������Ӧ�õ�ֵ�����ĵ���,����������ÿ��ֵ��������.
�����ֻ��Ҫ��������һ��ֵ������������,������ڵ���������ǰ����@����.
����: {$articleTitle|@count}(�⽫���� $articleTitle ���������Ԫ�ص���Ŀ)????

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.