Design question
| From: | Luc Saint-Elie | Date: | Fri, 13 Jul 2001 09:49:50 +0000 |
| Subject: | Design question | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1152@lists.php.net to get a copy of this message | ||
Hello,
This is probably a very basic question but...
Context :
======
A website with a main template (lets call it index.tpl) that calls a lot of sub-
templates and a main central one where the main content is displayed.
Depending on the navigation chosen by the visitor the main sub-templates
changes.
The url are of the form
/index.php ?screen=news
for the news or
/index.php ?screen=todolist
for the todo list and so on
In order to do this there are two ways (and perhaps more, its basicalyy my
question)
Way 1 :
======
In the index.tpl have a list of
{if $screen eq "news"}
{include file= "clientname.news.tpl"}
{else if $screen eq " todolist "}
{include file= "clientname.todolist.tpl"}
....
{/if}
Way 2
====
In the index.tpl have only
{include file=$clienttemplate }
and in index.php
switch($screen) {
case 'news' : $clienttemplate = clientname.news.tpl ;
break ;
case 'todolist' : $clienttemplate = clientname.todolist.tpl ;
break ;
....
}
The question is :
In PHP (and perhaps in other languages) for a huge number of options, switch is
quicker than if
So the logical choice would be to use way #2
But in this case the switch must be added in all .php files making the site
maintenance a real assle
(each time a new template to be included is added, all .php files must be
updated)
On the other hand using way #1 allow to only one file (the index.tpl) to
maintain... but is slower.
What is the right approach ?
Luc