Hey there! any question in your mind? Ask It Now!.

Popular Categories





How to use smarty with multiple pages?

+1 vote
220 views
asked in Programming by duke Expert (5,813 points)

hello guys can you help me on this, i am writting this

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?

1 Answer

+3 votes
answered by swag31 (1,430 points)
selected by duke
 
Best answer

you can try this :

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

but how you changing the frontcontroller  you can use :

$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;

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




$smarty->assign('page',$page);
$smarty->assign('content',$content);
$smarty->display('index.htm');
commented by Himanshu Expert (5,940 points)
Nice explanation... @swag it helped me too thanks !

Related Questions

+6 votes
3 answers 6,836 views
+4 votes
1 answer 916 views
+1 vote
0 answers 94 views
+2 votes
1 answer 139 views
0 votes
1 answer 247 views
0 votes
1 answer 405 views
+4 votes
1 answer 140 views
+4 votes
5 answers 718 views
0 votes
1 answer 9,844 views
+2 votes
3 answers 283 views
asked in Programming by jatin Expert (3,823 points)

Not a Member yet?

Ask to Folks Login

My Account
642 Folks are online
55 members and 587 guest online
Your feedback is highly appreciated