Re: Arguments for Smarty

From: Date: Fri, 07 Dec 2001 12:56:12 +0000
Subject: Re: Arguments for Smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2189@lists.php.net to get a copy of this message
Using Smarty, you have an efficient means to separate you design logic from your script/data retrieval logic. You could achieve some measure of this directly in PHP, but you would have to change you coding style significantly to do so. My early learning with PHP certainly produced valid HTML, but it was so intertwined with the script that it was much more difficult to deal with layout and pure HTML issues that when using Smarty. > 2. Smarty allows me to cache the PHP pages in HTML. > a. If I am writing dynamic database driven sites so I probably won't want > this anyway. Even with a dynamic db based application, caching has merit. Queries can be expensive, if you are able to cache the results, and the clear the cache as appropriate when the data changes, you gain significant benefits. > When doing sections in your template, you need to send an array of ALL the > data that will be shown in a section. What if you want to show 10,000 > records where each record is 1K in size? I see memory a resource usage > problems with that. If you do not send it all, how will you display it? I have not checked the source, but I believe they reference the original array, not make a copy so the resource drain should not be significantly more than loading it in the first place. > For example, coming from the PHPLIB templates we used to use, the way you > show database results is to assign each record one at a time using blocks. > So you are rendering each line of the result set and that means that > resource requirements are significantly less (to be fair, it depends on how > you handle the templates and parsing. A bad programmer could get back to > the 10,000 x 1K memory issue above). I don't see functionality from Smarty > to do this. It seems to be an all-or-nothing proposition when you do > sections. You need to send ALL the data to the template and it loops > through the array. Is there some "block" type functionality that will let > the looping happen inside the PHP file and call a smarty template per > record? I am thinking yes, but it means you would need to render the header > first, then the records, then the footer. ?? Don't retrieve the whole array, use some kind of a pager class in your script and only load and assign the portion of the array that you intend to display. This required more coordination between the designers and the developers but it is certainly doable. Hope some of those answers help. Regards. Jason ----- Original Message ----- From: "Pablo" <phpshop@phpshop.org> To: <smarty@lists.ispi.net> Sent: Friday, December 07, 2001 5:13 AM Subject: [smarty] Arguments for Smarty > [Moved from another thread, sorry I hit reply instead...] > Just a curious comment and question: > > I have been using Smarty and really enjoy using it. I had to learn how to > be able to loop through database results and deal with multi-dimensional > arrays and such. That kind of threw me for a loop and to be honest has been > the largest learning curve so far with smarty. But now I finally understand > how to do things (mostly, sometimes I need to go back to the docs). But, > the more I know, the more I am asking myself some fundamental questions > about Smarty. > > OK, so now that I am a Smarty "developer" I keep thinking that everything I > do in my templates is essentially replacing PHP-tags for Smarty-tags. I am > still programming inside my HTML, but I simply replaced the language. No > HTML separation from programming language. > > So I am sitting here staring at my template trying to figure out why I am > using Smarty instead of PHP. So far, here's what I've got in the mode of a > comparison: > > 1. Smarty allows me to "compile" templates to PHP. > a. If I used PHP from the beginning there is no need for this. > 2. Smarty allows me to cache the PHP pages in HTML. > a. If I am writing dynamic database driven sites so I probably won't want > this anyway. > Plus, it's not that far fetched to write a caching routine for regular > PHP/HTML files. > 3. Smarty allows me to include other templates inside the current template > using the "include" tag > a. PHP allows me to do the exact same thing using the "include" statement. > 4. Smarty is a little hard to learn (sections) at first, but once you get it > you're off and running. > a. I already know PHP. > 5. Smarty allows you to write custom tags. > a. With PHP you can create new functions or classes. > 6. Smarty allows if/elseif/else/endif construct for conditions. > a. PHP does too. And also offers a bit more :) > > I am not trying to make waves here, but I am hoping for an honest response > to this. I am trying to justify making people learn Smarty and my arguments > are being batted down one after the other. I need help to counterattack the > points above or to look for things that Smarty offers that are better than > the PHP/HTML alternative. > > One other thing I would like to comment on: > > When doing sections in your template, you need to send an array of ALL the > data that will be shown in a section. What if you want to show 10,000 > records where each record is 1K in size? I see memory a resource usage > problems with that. > > For example, coming from the PHPLIB templates we used to use, the way you > show database results is to assign each record one at a time using blocks. > So you are rendering each line of the result set and that means that > resource requirements are significantly less (to be fair, it depends on how > you handle the templates and parsing. A bad programmer could get back to > the 10,000 x 1K memory issue above). I don't see functionality from Smarty > to do this. It seems to be an all-or-nothing proposition when you do > sections. You need to send ALL the data to the template and it loops > through the array. Is there some "block" type functionality that will let > the looping happen inside the PHP file and call a smarty template per > record? I am thinking yes, but it means you would need to render the header > first, then the records, then the footer. ?? > > I thank you for the time invested in reading and responding to this email! > > Pablo > > > --- > You are currently subscribed to smarty as: sweatjejm@home.com > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/

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