Re: [SMARTY] Is there a way to include different files from a template?

From: Date: Thu, 16 May 2002 11:57:31 +0000
Subject: Re: [SMARTY] Is there a way to include different files from a template?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4214@lists.php.net to get a copy of this message
Peter, What follows is pseudo code incomplete. I don't know if its the "right way" to do this , but I do this this way and it works well. 1 ) I have a function like this in a separate file : function getDisplay($connecteurs) { $display = array(); switch ($connectors['t']) {
        case 'news'     : $display['1'] = 'foodir/bartpl1.tpl';
                                    $display['2'] = 'foodir/bartpl2.tpl';
                                    $display['3'] = 'foodir/bartpl3.tpl';
                                    $display['4'] = 'foodir/bartpl4.tpl';
                                    $display['5'] = 'foodir/bartpl5.tpl';
                                    $display['6'] = 'foodir/bartpl6.tpl';
                                    return $display;
                                    break;
etc..... In my *.php file i do : [....] include 'lib/myFileWithgetDisplayFunction.php'; $connectors = array('t' => $_GET['t'] ); $smarty->assign('bloc', getDisplay($connectors)); [...] And in the *tpl file : {include file=$bloc.1}<br /> {include file=$bloc.2}<br /> {include file=$bloc.3} So if the url is for this example index.php?t=news the switch -> case : "news' is fired. Passing an array to getDisplay i can set different sub templates to the same url using additional variables with for example for index.php?t=news&boss=yes
$connectors = array('t'              => $_GET['t']
                              'ismyboss' => $_GET['boss']
                              );
$smarty->assign('bloc', getDisplay($connectors)); and in the getDisplay() definition file : function getDisplay($connecteurs) { $display = array(); switch ($connectors['t']) {
        case 'news'     : $display['1'] = 'foodir/bartpl1.tpl';
                                    $display['2'] = 'foodir/bartpl2.tpl';
                          switch ( $connectors['ismyboss'] ) {
                                       case 'yes' :  $display['3'] = 'foodir/clientreport.tpl';
                                                          break;
                                       case 'no' :  $display['3'] = 'foodir/newbikepicture.tpl';
                                                          break;
                                            } 
                                    $display['4'] = 'foodir/bartpl4.tpl';
                                    $display['5'] = 'foodir/bartpl5.tpl';
                                    $display['6'] = 'foodir/bartpl6.tpl';
                                    return $display;
                                    break;
The handy part is that you can change the siyte behavior with only modifying the file where getDisplay() is defined (and the call in the *.php file of course) Hope this helps (and hope this is clear :) ) Luc At 13:32 16/05/2002 +0200, Peter Schumacher wrote:
Hi Guys, I'm working on a site that has the usual news, calendar etc. I know that it's possible to include a template from a template. But is it possible to specify this in a dynamic way? An example, // Main Template bla bla bla if $mode=news include news.tpl if $mode=calendar include calendar.tpl bla bla bla Regards, Peter Schumacher


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