O'Reilly logo

Building PHP Applications with Symfony™, CakePHP, and Zend® Framework by Leszek Nowak, Karol Przystalski, Bartosz Porebski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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!

Lewis Carroll

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required