To include or not to include ?

From: Date: Wed, 05 Feb 2003 23:54:59 +0000
Subject: To include or not to include ?
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7541@lists.php.net to get a copy of this message
Hello, I started to read the manual and code samples of Smarty while designing a generic web page. The template for a generic index.tpl web page has been divided in header.tpl, menu1.tpl, menu2.tpl, content.tpl and footer.tpl, this way : ----index.tpl---- {include file=header.tpl title=$title} {include file=menu1.tpl} {if $show_menu2 == 1} <TABLE> <TR> <TD>{include file=menu2.tpl}</TD> <TD>{include file=content.tpl}</TD> </TR> </TABLE> {else} {include file=content.tpl} {/if} {include file=footer.tpl} I simplified a little bit the real template. As you can imagine, there is a lot of dynamic data in the included templates but it seems that you have to pass variables to included templates as for header.tpl in the example above. It's not really easy to do that if you have a lot of variables. So, can we in this case imagine another solution : - Remove (or simplify) index.tpl - Create index.php script with several 'Smarty' objects - Display these objects in correct order Example : ----index.php---- [... variables init, database selects ...] $header = new Smarty; $menu1 = new Smarty; if ( $menu2_exists ) $menu2 = new Smarty; $content = new Smarty; $footer = new Smarty; [... variables init, database selects ...] $header->display(); $menu1->display(); if ( $menu2_exists ) { display_HTML_table_start(); $menu2->display(); display_HTML_table_middle(); $content->display(); display_HTML_table_end(); } else $content->display(); $footer->display(); What is your opinion on it ? Can it be a correct approach in case of heavily dynamic content in templates or does this require too many resources to be interesting in real life ? PS: Please be kind about the code quality. :)) It's only there to explain what i mean. -- Best regards, Artur Pydo.

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