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

Popular Categories





How to use smarty with multiple pages?

+1 vote
249 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 7,055 views
+4 votes
1 answer 1,066 views
+1 vote
0 answers 120 views
+2 votes
1 answer 156 views
+4 votes
1 answer 167 views
+4 votes
5 answers 771 views
0 votes
1 answer 9,923 views
+2 votes
3 answers 315 views
asked in Programming by jatin Expert (3,823 points)
+2 votes
1 answer 177 views

Not a Member yet?

Ask to Folks Login

My Account
438 Folks are online
3 members and 435 guest online
Your feedback is highly appreciated