However, you??™ll really
want to use many of these features from within the presentational layer??”for example, to
ensure that an article author??™s first and last names are capitalized within the article
description. Recognizing this fact, the Smarty developers have incorporated many
such presentation-specific capabilities into the library. This section introduces many
of the more interesting features.
Before starting the overview, it??™s worth first introducing Smarty??™s somewhat
nontraditional variable modifier syntax. While of course the delimiters are used to signal
the requested output of a variable, any variable value requiring modification prior to
output is followed by a vertical bar, followed by the modifier command, like so:
{$var|modifier}
You??™ll see this syntax used repeatedly throughout this section as the modifiers are
introduced.
Capitalizing the First Letter
The capitalize function capitalizes the first letter of all words found in a variable. An
example follows:
CHAPTER 19 ?– TEMPLAT ING WITH SMARTY 481
$smarty = new Smarty;
$smarty->assign("title", "snow expected in northeast");
$smarty->display("article.tpl");
The article.tpl template contains the following:
{$title|capitalize}
This returns the following:
Snow Expected In Northeast
Counting Words
The count_words function totals up the number of words found in a variable. An
example follows:
$smarty = new Smarty;
$smarty->assign("title", "Snow Expected in Northeast.
Pages:
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563