These
solutions are known as templating engines, and they go a long way toward eliminating
the enormous difficulties otherwise imposed by lack of layer separation. This chapter
introduces this topic, and in particular concentrates upon the most popular PHPspecific
templating solution: Smarty.
472 CHAPTER 19 ?– T EMPLAT I NG WITH SMARTY
What??™s a Templating Engine?
As the opening remarks imply, regardless of whether you??™ve actually attempted it, it??™s
likely that you??™re at least somewhat familiar with the advantages of separating a Web
site??™s logic and presentational layers. Nonetheless, it would probably be useful to
formally define exactly what is gained by using a templating engine.
Simply put, a templating engine aims to separate an application??™s business logic
from its presentational logic. Doing so is beneficial for several reasons, two of the
most pertinent are the following:
??? You can use a single code base to generate output for numerous formats: print,
Web, spreadsheets, e-mail-based reports, and others. The alternative solution
would involve copying and modifying the code for each target, resulting in
considerable code redundancy and greatly reducing manageability.
??? The designer (the individual charged with creating and maintaining the interface)
can work almost independently of the application developer because the
presentational and logical aspects of the application are not inextricably intertwined.
Pages:
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552