'SmartyException' with message 'Missing template name' in Smarty

只愿长相守 提交于 2021-01-29 19:48:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!