Chapter 12. Templating with Smarty

As your projects grow more complicated, particularly when you start working with web designers, there’s likely to come a time when the convenience of separating the program code from the presentation becomes apparent.

Initially PHP itself was developed as a sort of templating system with a few elements of programming and flow control. But it quickly developed into the powerful programming language we know today. Some developers still treat it a little like a templating system, though, as in the case of the WordPress blogging platform, which uses a set of template PHP files for each theme.

However, allowing presentation to become intertwined with programming can create problems, because it means that the layout designers have full access to the source code and can unwittingly make dangerous changes to it. Additionally, using a separate templating system frees up designers to modify templates to their hearts’ content, safe in the knowledge that nothing they do can break your program code; it leads to much greater flexibility.

It’s also an incredible boon when your boss comes along and demands a whole load of design changes, because all you have to do is modify the template files. Without a templating system, you’d very likely have to search through many files of PHP code to make the necessary modifications.

Note

Some programmers like to stick with just the programming language when they develop web pages, and don’t use templates. If you’re one of them, ...

Get Learning PHP, MySQL, and JavaScript 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.