0

I have Smarty 3.1 working with my website for JUST Index.php.

Now, how would I add on and make a contact page?

1) Make contact.php and make a whole new template?

2) Make it index.php?page=contact ??

3) Make contact.php and use the template and pass variables to template making it show contact stuff....?

user1973551
  • 29
  • 1
  • 8

1 Answers1

1

2) Make it index.php?page=contact

The better approach is use a centralized system. You could get the page value and load the appropriate template.

For example:

switch ($page) {
    case "home":
        $template="home.tpl";
        break;
    case "contect":
        $template="contact.tpl";
        break;
    default:
        $template="404.tpl";
        break;
}

$smarty->display($template);
Some_dude
  • 136
  • 1
  • 5
  • Is default: basically an else? – user1973551 Feb 04 '13 at 04:32
  • What is the purpose of the ability of a template if you're just going to do this anyway? You're building a template per page, isn't the point to majorly save memory? – grepsedawk Feb 04 '13 at 04:43
  • @Alex.Piechowski yeah smarty don't contemplate the routing system, but you can save alot of work using template engines, reduce redundant processes and can also help save physical memory. – Some_dude Feb 04 '13 at 16:23