Listing 19-4. The index.tpl Template??™s Application Logic
require("Smarty.class.php");
$smarty = new Smarty;
// Assign two Smarty variables
$smarty->assign("name", "Jason Gilmore");
$smarty->assign("title", "Smarty Rocks!");
// Retrieve and output the template
$smarty->display("welcome.tpl");
?>
The resulting output is offered in Figure 19-1.
CHAPTER 19 ?– TEMPLAT ING WITH SMARTY 479
Figure 19-1. The output of Listing 19-4
This elementary example demonstrates Smarty??™s ability to completely separate
the logical and presentational layers of a Web application. However, this is just a
smattering of Smarty??™s total feature set. Before moving on to other topics, it??™s worth
mentioning the display() method used in the previous example to retrieve and render
the Smarty template. The display() method is ubiquitous within Smarty-based scripts
because it is responsible for the retrieval and display of the template. Its prototype
looks like this:
void display(string template [, string cache_id [, string compile_id]])
The optional parameter cache_id specifies the name of the caching identifier, a
topic discussed later in the section ???Caching.??? The other optional parameter, compile_id,
is used when you want to maintain multiple caches of the same page. Multiple caching
is also introduced in a later section ???Creating Multiple Caches per Template.???
Smarty??™s Presentational Logic
Critics of template engines such as Smarty often complain about the incorporation of
some level of logic into the engine??™s feature set.
Pages:
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561