czLukasss
czLukasss

Reputation: 750

Smarty - catching "Unable to load template" error

i use automatic loading .tpl files by get parameter.

The parameter might be wrong and on next move it stops by error "Smarty: Unable to load template".

Can i catch this error and redirect page to some default template?

Thank you very much!

$seo = $params[0];
$smarty->display($seo . '.tpl');

Upvotes: 0

Views: 4636

Answers (1)

OptimusCrime
OptimusCrime

Reputation: 14863

Smarty has a function to check if a template exists.

From the documentation:

if( !$smarty->template_exists($mid_template) ){
    $mid_template = 'page_not_found.tpl';
}

You can for example use it like this:

if($smarty->template_exists($template)) {
    header("Location: error.html");
    exit();
}
$smarty->display($template);

Upvotes: 1

Related Questions