is_cached

is_cached -- 

bool is_cached ( string template [, string cache_id])

This returns TRUE if there is a valid cache for this template. This only works if caching is set to true.

Example 1. is_cached

<?php
$smarty
->caching = true;

if(!
$smarty->is_cached("index.tpl")) {
// do database calls, assign vars here
}

$smarty->display("index.tpl");
?>

You can also pass a cache id as an optional second parameter in case you want multiple caches for the given template.

Example 2. is_cached with multiple-cache template

<?php
$smarty
->caching = true;

if(!
$smarty->is_cached("index.tpl", "FrontPage")) {
  
// do database calls, assign vars here
}

$smarty->display("index.tpl", "FrontPage");
?>