Best way to use Multiple Pages on Smarty

php, smarty

Solution

Yes,

Maybe you could update the $page variable to the following:

<?php
$page = isset($_GET['page']) ? $_GET['page'] : '';
?>

But the way you are changing pages with a frontcontroller is the good way. You can do some upgrading... My workflow;

- Display index.html file and load in the frontcontroller other TPL/HTML files in that index.htm file.

Something like:

$content = "";
$page = isset($_GET['page']) ? $_GET['page'] : '';

// FRONTCONTROLLER
switch ($page) {
    case 'stack':
        require_once('includes/stack.php');
        $content = getContent();
        break;

    case 'overflow': 
        require_once('includes/overflow.php');
        $content = "overflow....";
        break;

    default:
        $content = "blalala";
        break;
}

$smarty->assign('page', $page);
$smarty->assign('content', $content);
$smarty->display('index.htm');

Problem

Is this the most effective way to use smarty with multiple pages?: ``` if (empty($_GET[page])) { $template = "home.tpl"; $smarty->assign('pagename', ' - Home'); } else { $page = $_GET["page"]; switch ($page) { case "home": $template = "home.tpl"; $smarty->assign('pagename', ' - Home'); break; case "contact": $template = "contact.tpl"; $smarty->assign('pagename', ' - Contact us'); break; case "verify": $template = "verify.tpl"; $smarty->assign('pagename', ' - Verify your account'); break; default: $template = "404.tpl"; break; } } $smarty->assign('sitename', $sitename); $smarty->display($template); ``` What if I have "log-in" and "user area" and everything? How can I make them each do their own functions cleanly?

Original source