Chapter 9. Templates
Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!
WHAT'S IN THIS CHAPTER?
Creating an image gallery using Lightbox
Integrating chosen template engines with frameworks
Pros and cons of using template engines
Overview of popular template engines
Previous chapters discussed frameworks' innards; this chapter focuses on the presentation layer instead. So what are these template engines, and why are they so important? In web development, PHP code processes all data, so it's responsible for the business logic. The view layer represented by template engines is the presentation part of your site. A template engine allows you to develop websites with various different layouts or themes for the same core functionality.
Template engines are very popular tools among PHP projects that do not use any frameworks. Despite their popularity however, they are not often used along with web frameworks. In this chapter, we will explain why it is so and show a few tricks to make them get along with each other.
CREATING A SIMPLE IMAGE GALLERY BY USING HELPERS AND LIGHTBOX
The following script renders an index page. It uses some PHP functions to generate the page content intertwined with HTML blocks. (This is a programming style from the year 2000, when PHP was a new thing altogether.)
<?php $head_title = 'Title'; $block_name ='News block'; display_content(); function_1(); function_2(); ?> <html> <head> ...
Get Building PHP Applications with Symfony™, CakePHP, and Zend® Framework now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.