Re: Design question : synthesis

From: Date: Fri, 13 Jul 2001 11:53:29 +0000
Subject: Re: Design question : synthesis
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1156@lists.php.net to get a copy of this message
I have a third way that I deal with the problem. I have a variable $view and in the site script I do switch($view) { case 'news': case 'todo': } and in my template I have: the main page, navigation, etc. {if $view == 'news'} {elseif $view == 'todo'} {else} <h1>This view mode not supported!</h1> {/if} This allows me to encapsulate the entire functionality in a single php script and a single template file (which I believe will promote maintainability in the long term). I then overcome speed issues with appropriate use of Smarty caching, using different cache id's for each of the views. Hope that helps. Jason ----- Original Message ----- From: "Luc Saint-Elie" <luc@saint-elie.com> To: <smarty@lists.ispi.net> Sent: Friday, July 13, 2001 6:21 AM Subject: [smarty] Design question : synthesis > Hello, > > At first I was afraid my question was really stupid, at the end it is but the > answers are not. > So here is a little synthesis hopping this could help. > > From the very straightforward Mike's approach (that requires a very vell > defined file naming scheme) to Victor database based solution, there are huge > differences.... > I will probably go for Adi approach that seem to fit better the way I work. > > The question (short version) was : > When a sub-template is changed based on an url variable (index.php? > screen=variablename) > -> what is the best way to deal with the variable/template association > management ? > > > ===================== Mike ================================ > have you tried in index.tpl: > > {include file= "clientname.$screen.tpl"} > > > ===================== Victor ================================ > For my site, where I have a sort of similiar layout, I've made a table in a > database where all the pages are stored. Like: > > news | news.tpl | script.news.php > todo | todo.tpl | script.todo.php > > etc.. > > then I just do a SELECT * FROM mytable WHERE id='$id'; > > This is good because: > * If I add a new page I only have to add a row in the database (can be done > online!) > * The same goes for renaming the page title which I also have stored in the > same database. > * Flexible.. Extendable.. better looking code.. And more I guess. > > Well, it's only a suggestion. No approach is the _best_. > > =========================== Adi ====================================== > Well you don't really need the whole switch in all the files. > Do could do something like: > > -- screen-selection.inc.php -- > function get_screen_tempalete($screen) { > > switch($screen) { > case 'news' : > return = "clientname.news.tpl"; > break ; > case 'todolist' : > return "clientname.todolist.tpl"; > break ; > default: > return "screen-unknown.tpl"; > } > } > > -- index.php -- > require "screen-selection.inc.php"; > $smarty->assign("clienttemplate", get_screen_template($screen)); > > -- index.tpl -- > {include file=$clienttemplate } > ===================================================================== > > --- > You are currently subscribed to smarty as: sweatjejm@home.com > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at m¶$‰qÜö > 5µV+http://www.phpinsider.com/php/code/Smarty/ >

« previous php.smarty.general (#1156) next »