Templating Your Site with Smarty

Sep 24, 2009 Author: Dr_ViRuS

Most sites have a consistent look and feel. Although the dynamic content in the middle of the page may change, there's usually a header, a navigation bar on the side, and maybe an advertisement or two. There are simple ways to achieve this, from custom header-printing functions to include files. Depending on the size of your site, these solutions may work fine, but the larger and more complicated your content becomes, the more tedious making changes can get.

The most common templating solution is Smarty (http://smarty.net). With Smarty, you create templates with variables. In other words, you can create one HTML file with placeholders for PHP-created data. In addition, you can include other Smarty templates inside a template, allowing you to better organize and edit pieces of your site. Once you get really familiar with Smarty, you can cache data and speed up your site considerably, but that's an advanced technique outside the scope of this book. What follows is enough to get you up and running for most sites.

Installing Smarty


views 3918
  1. Add New Comment