Just confirming, the code should end up looking like this:
PHP Code:
if (isset($templatecache[$templatename])) {
$template=$templatecache[$templatename];
} else {
if ($bbuserinfo['userid']=='1') {
echo "<b>$templatename</b> isn't cached!<br>";
}
$gettemp=$DB_site->query_first("SELECT template FROM template WHERE title='".addslashes($templatename)."' AND (templatesetid=-1 OR templatesetid=" . intval($templatesetid). ") ORDER BY templatesetid DESC LIMIT 1");
$template=$gettemp[template];
$templatecache[$templatename]=$template;
}