问题
I got the error saying "SmartyException' with message 'Missing template name...". I'd love to show the different page using display() in Smarty. I get the value from the url and deferenciate the page. I tried concatenate the single quote, but it doesn't really work. Any helps appreciate. index.html , confirm.html , finish.html exist in contact folder in a template directory.
switch($_GET['param']) {
case 1: confirmation();
break;
case 2: send_email();
break;
case 3: finish();
break;
}
function confirmation(){
echo 'index page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/index.html');
$url = '\'contact/index.html\'';
}
function send_email(){
echo 'confirmation page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/confirm.html');
$url = '\'contact/confirm.html\'';
}
function finish(){
echo 'finish page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/finish.html');
$url = '\'contact/finish.html\'';
}
//
$smarty->assign('css', "contact");
//$smarty->display('contact/index.html');
$smarty->display($url);
回答1:
This is because you make $url
a local variable in each function. You should create global variable and return $url
in each function as in the following code:
$url = '';
switch($_GET['param']) {
case 1:
$url = confirmation();
break;
case 2:
$url = send_email();
break;
case 3:
$url = finish();
break;
}
function confirmation(){
echo 'index page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/index.html');
$url = 'contact/index.html';
return $url;
}
function send_email(){
echo 'confirmation page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/confirm.html');
$url = 'contact/confirm.html';
return $url;
}
function finish(){
echo 'finish page';
//$smarty->assign('css', "contact");
//$smarty->display('contact/finish.html');
$url = 'contact/finish.html';
return $url;
}
//
$smarty->assign('css', "contact");
//$smarty->display('contact/index.html');
$smarty->display($url);
By the way I removed also single quotes from $url
in each function because they don't seem to be necessary at all.
来源:https://stackoverflow.com/questions/24987975/smartyexception-with-message-missing-template-name-in-smarty