Book Image

Smarty PHP Template Programming and Applications

By : Hasin Hayder, Joao Prado Maia, Lucian Gheorghe
Book Image

Smarty PHP Template Programming and Applications

By: Hasin Hayder, Joao Prado Maia, Lucian Gheorghe

Overview of this book

<p>Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work with Smarty templates, which are HTML files with simple tags while programmers work with the underlying PHP code. The Smarty engine brings the code and templates together. The result of all this is that designers can concentrate on designing, programmers can concentrate on programming, and they don't need to get in each others way so much. Even if you are developing a site on your own, Smarty is a powerful way to make your code clearer to you and others, as well as easier to debug and modify later.</p>
Table of Contents (18 chapters)
Smarty PHP Template Programming and Applications
Credits
About the Authors
About the Reviewer
Preface
Index

Advanced Caching Features


While it may seem that the caching features outlined so far are very useful (and they are!), they will quickly fall short for a semi-complex website. Take for example, a portal-like website with sections like news, weblogs, and photos. You may want to cache the output of all specific news items, and re-generate them in 5 days. On this specific case, the existing caching functionality will not be enough, as the cache is associated with a template file, but this template file is re-used for all news items.

The feature that is available and overcomes this apparent lack of functionality is the ability to create multiple caches per template file. You do that by passing a second parameter to the display method, which Smarty will use that to create a sub-directory under the cache directory to hold the cache files. Take the following PHP script as an example:

<?php
include_once(‘libs/smarty.class.php’);
$smarty = new Smarty;
$smarty->caching = 1;

// $_GET[‘id’] holds...