Re: Example Websites

From: Date: Thu, 08 Nov 2001 15:27:44 +0000
Subject: Re: Example Websites
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1866@lists.php.net to get a copy of this message
Hello, Having tried such a process for a even smaller project, I would fire some alarms on the facts that between "what would be great" and "what is realistic"... There is a huge gap. Of course a full of bells and whistles Smarty based web site would be great, but perhaps its more realistic to think to some kind of guide lines (in FAQ form ?) for the "best way" to do classical operations with Smarty As an example, one thing every Smarty based web site will do is to switch template based on some input. For this very basic and standard operation there are numerous ways, that can be dided in two big categories : - a loop through an array in the template - a loop (a switch or any thing this way) in a php files that send the result to the template For my own use I choose the second solution (after have started with the first) because its easier for me to avoid logic in the template as much as possible Is it the right choice ? Even for the second solution there are several ways to proceed, I use the following (not sure at all this is the "best way" to do this) In index.php //------- require 'lib/tempate.switch.php'; $menu = array(); $menu = get_screen_template($t, $a); $tpl->assign('bloc1',$menu['bloc1'] ); $tpl->assign('bloc2',$menu['bloc2'] ); $tpl->assign('bloc3',$menu['bloc3'] ); $tpl->assign('bloc4',$menu['bloc4'] ); $tpl->assign('bloc5',$menu['bloc5'] ); $tpl->assign('bloc6',$menu['bloc6'] ); $tpl->assign('centre',$menu['centre'] ); //------- in template.switch.php //----------------- function get_screen_template($t, $a) { $display = array(); switch ($t) { case 'news' : $display['bloc1'] = 'foo1.tpl'; $display['bloc2'] = 'foo2.tpl'; $display['bloc3'] = 'foo3.tpl'; $display['bloc4'] = 'foo4.tpl'; if ($a ==’bar’) { $display['bloc5'] = 'foo5.tpl'; }else { $display['bloc5'] = 'foo5bis.tpl'; } $display['bloc6'] = 'foo6.tpl'; $display['centre'] = 'foo7.tpl'; return $display; break; ... in the main template (index.tpl) ... {include file=$bloc1} .... This allow me to switch templates based on the url (in get_screen_template($t, $a); $t is for template and $a is for action) so in the switch I can ad so if/the/else cause to modify the global organization for a specific url This is one way to do this template selection, I suppose its not by far the best and there are number of other ones. Its this kind of question a Smarty user (at least a basic on as I am) will have more than a beautiful web site... Luc

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