Re: [SMARTY] To include or not to include ?

From: Date: Thu, 06 Feb 2003 00:00:05 +0000
Subject: Re: [SMARTY] To include or not to include ?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7542@lists.php.net to get a copy of this message
Hello Artur! Actually you don't have to specfiy each variable when you include a template, any variables available in the current template are also available within the included template, so your first solution is good. /Nichlas ----- Original Message ----- From: "Artur Pydo" <artur@pydo.org> To: <smarty-general@lists.php.net> Sent: Thursday, February 06, 2003 12:54 AM Subject: [SMARTY] To include or not to include ? > 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. > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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