Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
791 views
in Technique[技术] by (71.8m points)

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

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...