");
$smarty->assign("body", "More than 12 inches of snow is expected to
accumulate overnight in New York.");
$smarty->display("countwords.tpl");
The countwords.tpl template contains the following:
{$title} ({$body|count_words} words)
{$body}
This returns the following:
Snow Expected in Northeast (14 words)
More than 12 inches of snow is expected to accumulate overnight in New York.
Formatting Dates
The date_format function is a wrapper to PHP??™s strftime() function and can convert
any date/time-formatted string that is capable of being parsed by strftime() into
some special format. Because the formatting flags are documented in the manual
and in Chapter 12, it??™s not necessary to reproduce them here. Instead, let??™s just jump
straight to a usage example:
482 CHAPTER 19 ?– T EMPLAT I NG WITH SMARTY
$smarty = new Smarty;
$smarty->assign("title","Snow Expected in Northeast");
$smarty->assign("filed","1172345525");
$smarty->display("dateformat.tpl");
The dateformat.tpl template contains the following:
{$title}Submitted on: {$filed|date_format:"%B %e, %Y"}
This returns the following:
Snow Expected in NortheastSubmitted on: June 24, 2007
Assigning a Default Value
The default function offers an easy means for designating a default value for a particular
variable if the application layer does not return one:
$smarty = new Smarty;
$smarty->assign("title","Snow Expected in Northeast");
$smarty->display("default.
Pages:
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564