RE: Smarty and speed

From: Date: Fri, 07 Dec 2001 11:06:50 +0000
Subject: RE: Smarty and speed
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2187@lists.php.net to get a copy of this message
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

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