What are some potential pitfalls of using Smarty for templating in PHP?

One potential pitfall of using Smarty for templating in PHP is the performance overhead it can introduce compared to plain PHP templating. To mitigate this, you can cache the compiled templates to reduce the parsing overhead on subsequent requests.

// Enable caching in Smarty
$smarty->caching = true;
$smarty->cache_lifetime = 3600; // Cache lifetime in seconds

// Check if template is cached, if not, fetch and display
if (!$smarty->isCached('template_name')) {
    // Fetch data and assign to template variables
    $data = fetchData();
    $smarty->assign('data', $data);
    
    // Display the template
    $smarty->display('template_name');
} else {
    // Display cached template
    $smarty->display('template_name');
}