Codice PHP:
function usaBiglietteria()
{
$carrello = $_SESSION['carrello'];
if (!$carrello)
{
$nprod = 0 ;
}
else{
$prodotti = @explode(',',$carrello);
$nprod = count($prodotti);
}
return $nprod;
}
nel file php:
$nprod = usaBiglietteria();
$smarty->assign('nprod', $nprod);
$smarty->assign('prodotti', $prodotti);
$smarty->display('carrello.tpl');
nel file carrello.tpl:
{if $nprod == 0}
Il carrello è vuoto.
{else}
Ci sono [B] {$nprod} [/B] biglietti nel carrello
{/if}