Re: include_php options / best practices

From: Date: Fri, 11 Jun 2004 00:03:32 +0000
Subject: Re: include_php options / best practices
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11442@lists.php.net to get a copy of this message
Sarah Gray wrote:
Hi -- What would be a good way to have the output from two different .php files on a given smarty template? So that the whole page is displayed by $t->display('index.tpl') where index.tpl includes header.tpl, footer.tpl, menus.tpl (see drawing below) But it would also have a changing template in the middle of the page that would be called depending on which menu option is selected. Kind of like how a frameset would behave, except not a frameset. (A big table). So in my drawing, user-selected options are designated by **. Here the user has clicked *reports*, which generated the reports sub menu, and then clicked *eat report*. ___________________________________________
  LOGO       schedule | *reports*  | tests |
		(header.tpl)	           |
(menus.tpl) |
view report		                   |
print report                               |
*eat report*     *eat report content*	   |
                  (dynamic from menu)      |
|
             footer stuff here (footer.tpl)|
___________________________________________| The idea is that *eat.report* would show up in the middle area -- but it needs to call eat.report.php that has lots of variables it assigns to eat.report.tpl, which then shows up in the middle area. This area is obviously the body of the application. I could use {include_php file="content.php" page=$smarty.get.pagevar} where content.php would use the page var to redirect it's output to the appropriate page which will display the relevant template in the body area -- but include_php is being deprecated and I'm wondering what would be a better way? I looked at componentized templates, but don't think I could get away from calling a php page. In a nutshell this boils down to -- is it bad practice to include a php file in a template, if the sole purpose of that file is to call another template? And if it is bad practice and will be removed from smarty, is there a better way? And if missing something obvious here, please remind me :) Thanks, Sarah
I would suggest splitting your templates differently. Put the stuff above your "dynamic" template include in a header.tpl and the stuff below it in footer.tpl. Then, include header.tpl and footer.tpl in the other templates. Your PHP which does the $t->display() call should be the one choosing which template to use. The PHP that calls that should also assign the correct vars as necessary. So something like this: if($content1) { $t->display('content1.tpl'); } else { $t->display('defaultContent.tpl'); } header.tpl: This is the header footer.tpl: This is the footer content1.tpl: {include file="header.tpl"} Content 1 {include file="footer.tpl"} defaultContent.tpl: {include file="header.tpl"} Default Content {include file="footer.tpl"} If you don't like that solution, I would suggest that you still assign the vars for each page in the code that calls $t->display() (using a switch or if), then assign a special var which tells index.tpl which content template to include, then call $t->display('index.tpl'). index.tpl: header stuff {include file=$contentTemplate} footer stuff -- paperCrane <Justin Patrin>

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