Prev | Current Page 542 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

First, the delimiters,
denoted by curly brackets ({}), serve as a signal to the template engine that the data
found between the delimiters should be examined and some action potentially taken.
Most commonly, this action involves inserting a particular variable value. For example,
the $pagetitle variable found within the HTML title tags denotes the location where
this value, passed in from the logical component, should be placed. Farther down the
page, the delimiters are again used to denote the start and conclusion of an if conditional
to be parsed by the engine. If the $name variable is set to "Kirk", a special message
will appear; otherwise, a default message will be rendered.
Because most templating engine solutions, Smarty included, offer capabilities that go
far beyond the simple insertion of variable values, a templating engine??™s framework
must be able to perform a number of tasks that are otherwise ultimately hidden from
both the designer and the developer. Not surprisingly, this is best accomplished via
object-oriented programming, in which such tasks can be encapsulated. (See
Chapters 6 and 7 for an introduction to PHP??™s object-oriented capabilities.) Listing
19-2 provides an example of how Smarty is used in conjunction with the logical layer to
prepare and render the index.tpl template shown in Listing 19-1. For the moment,
don??™t worry about where this Smarty class resides; this is covered soon enough.


Pages:
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554