Most programmers would agree that it is a good practice to separate display elements from business logic. To illustrate this point, consider the example of a web designer working with a bad PHP programmer to develop a new web application.
Such projects often begin with the designer creating an HTML mockup of the site using his graphical HTML editor of choice. The bad programmer would then take this template and replace elements intended to be dynamic with PHP code.
Though seeming to be fast and easy at first, this methodology has some severe drawbacks that become obvious the first time the designer needs to make changes to the application's appearance. Most HTML editors would have trouble editing HTML tags embedded in a PHP file, especially looping code structures, like those a programmer might use to add rows to a table. Since the designer most likely doesn't know how to program in PHP, he would be unable to make the changes. It would instead be up to the programmer to make the changes. He would be forced to go through a time-consuming and error-prone process of updating his application so that its output matched the designer's new mockup. If, for example, a company were changing its standard web template, a great many applications would need to be modified in this way– a daunting task to be sure.
Clearly, separating an application's appearance from its business logic would be a good idea. An even better idea might be to use some form of templating system, so that if design changes needed to be made, they could be made in one place instead of in every application.
Marmot solves the problem of mixed display and business logic with its "Presentation Layer." With Marmot, a designer can create a "theme" that implements his design. When programmers write applications, they invoke generic methods that allow them to place content within the framework provided by the designer's theme. If, later, the designer makes changes to the theme, those changes will be instantly reflected in all of the applications that make use of the theme, with no intervention required by the programmer.
When a Marmot programmer interacts with the Presentation Layer, an Extensible Markup Language (XML) document containing the desired content is built behind-the-scenes. This XML document is then transformed by Extensible Stylesheet Language Transformations (XSLT) before being displayed. Though this is a relatively complicated process, it requires no interaction from the programmer.
In this chapter, we will discuss the methods by which a programmer interacts with the Presentation Layer.