What are the top PHP Templates Engines out there?

Is there one that stands above the rest?

As I learn PHP and build my e-commerce site, I would like to use a PHP Template ENgine, however, I do not have any background with them. (Actually, I'm still trying to learn what they are and why they matter! LOL)

The book I am using suggests SMARTY, but it seems like I saw some people slamming SMARTY a few years ago?! 😕

Also, is the "Zend Framework" a PHP Template Engine or is that something different?

**NOTE: My site architecture will use Object-Oriented Programming.

Thanks,

Amy

    I have not used any template engines. I have heard Smarty can be a bit of a resource hog, but it certainly seems to be the most popular -- I don't know if that's because it's good or just because it was the first one to gain wide-spread usage.

    I use the CodeIgniter framework for larger projects, making use of "views" (as in MVC), which are not "templates" in the Smarty sense, but does sort of serve the same purpose. I believe there are some templating add-ons available for CI should you (a) want to use "true" templates and (b) use Code Igniter.

    Zend Framework is similar to CI, but more extensive and perhaps generally at a slightly lower level. I've not used it, but I'm sure that it has available templating systems, either packaged with it and/or available separately from Zend or 3rd parties. (For that matter, I suspect it would not be all that difficult to incorporate Smarty into Zend, CI, or whatever -- just don't hold me to that. 😉 )

      NogDog;10924847 wrote:

      I have not used any template engines. I have heard Smarty can be a bit of a resource hog, but it certainly seems to be the most popular -- I don't know if that's because it's good or just because it was the first one to gain wide-spread usage.

      Funny, because the author of my e-commerce book chose it "because of its very good performance results, powerful features (such as template compilation and caching), and wide acceptance in the industry."

      I use the CodeIgniter framework for larger projects, making use of "views" (as in MVC), which are not "templates" in the Smarty sense, but does sort of serve the same purpose. I believe there are some templating add-ons available for CI should you (a) want to use "true" templates and (b) use Code Igniter.

      Well, I do want to learn and use the MVC model on my site. Will using Smarty prohibit me from using the MVC model??

      Can you help me get a better understanding of the difference between a "Template" and a "View"? (I'm only in Chapter 2.) 🙂

      FWIW, the author emphasizes using a 3-Tiered Architecture several times so far, so he seems like he knows how to build real-life, scalable systems. And as far as I can tell, 3-Tiered Architecture is synonymous with the Model-View-Controller model, right?? :queasy:

      I guess for now I'll just follow what he does since that is why I bought the book. However, I always like to think several steps ahead!

      Zend Framework is similar to CI, but more extensive and perhaps generally at a slightly lower level. I've not used it, but I'm sure that it has available templating systems, either packaged with it and/or available separately from Zend or 3rd parties. (For that matter, I suspect it would not be all that difficult to incorporate Smarty into Zend, CI, or whatever -- just don't hold me to that. 😉 )

      The Zend Framework is more how you code PHP and structure the files, right?

      Amy

        Roughly speaking - and based on my potentially flawed understanding -- a template is generally a [X]HTML text file that can contain special mark-up and/or place-holder text that the template engine reads and replaces with dynamic content. That text can even contain directives that will essentially result in looping through data (such as to display table rows). The supposed up-side of this is that the person creating the template only needs to know HTML/CSS plus the additional mark-up needed for the template actions. The down-side is that it's another "language" to learn, and one way or another it means another layer of reading a file, parsing it, and performing operations on it to generate the output.

        A "view" is simply another PHP file, with its purpose centered on generating [X]HTML output (or whatever other output type you want). If you were going to incorporate a template engine with a MVC framework, I would expect you would normally do it via the view file. Perhaps a good way to understand a view is to look at the CodeIgniter video tutorials (requires QuickTime): http://codeigniter.com/tutorials/.

          and one way or another it means another layer of reading a file, parsing it, and performing operations on it to generate the output.

          I believe that the point of Smarty is that it pre-compiles the template for faster rendering.

          http://www.smarty.net/rightforme.php

            etully;10924858 wrote:

            I believe that the point of Smarty is that it pre-compiles the template for faster rendering.

            http://www.smarty.net/rightforme.php

            Like I said, I've not used Smarty (yet). 🙂

            (And so far I have not run into a situation where I thought, "Gee, this would be easier to do with a template system." But then I've not been in a situation yet where I needed to provide a means for a non-PHP person to create the views, though I think I could give very similar functionality via CodeIgniter views with perhaps a few support functions. 😉 )

              amy.damnit;10924850 wrote:

              Well, I do want to learn and use the MVC model on my site. Will using Smarty prohibit me from using the MVC model??

              Nope. I use Smarty all the time as my view handler.

                Personally I've stayed away from Smarty but have done a bit of research into it when I was working with the zend framework.

                I think before you use any code library you need to ask yourself a few questions
                Am i going to release this application to the wider public?
                If its likely you going to release your development for the general public to work with using smarty is a good idea allowing people to easily implement their own templates/styles without having to understand your back end programming/methods.

                If you or a close knit team are the only likely developers learning smarty/getting them to learn smarty when it is unlikely to improve your development time and the extra server load it will add it's not worth abstracting your data any more when you can use basic short tags and alternative syntax to make your views as clean as possible.

                Is a designer or other non php person going to have to work with the application?
                If front end developers are going to be working directly on the files and dont have an understanding of php but could work their way round the smarty syntax it is worth using a templating engine. Otherwise again it goes to my previous point.

                Is the platform likely to change that I am developing on/for?
                If the application is likely to be installed on different servers/implementations that you have no control over using short tags can become an issue (<?=$var?> ) as they are disabled within some implementations. Smarty would be useful in this case.
                A similar thing is with PDO if you cannot be sure what database management system is going to be used on any of the application implementations PDO is ideal however if you know the DBMS is going to be MySQL it is more resource effective to use mysqli.

                  knowj,

                  Glad to see you again (finally)!!

                  I liked your response. 🙂

                  Well, my e-commerce site will be developed by me and is for me and will not change platforms, so based on what you wrote, Smarty wouldn't add much benefit.

                  This, of course, leads me to ask...

                  So what is the best way to implement the View layer in the MVC model if I am not using Smarty??

                  **NOTE: Remember, I am just learning PHP and do not know Smarty, and brought this topic up since it is how the author of my book plans to implement the Presentation layer.

                  That being said, I suppose it makes sense to just follow what the author of my books suggests. But always wanting to learn and do things better, I posed my questions here.

                  Thanks,

                  Amy

                    Probably the most straight-forward way would be to create the view as a web page with PHP functions where needed to process the dynamic data, and also to include the "boiler plate" parts of the page that do not change. Then your controller would simply include()/require() the desired view as needed.

                    This could be supported by a set of functions and/or methods to do common output tasks, so that the view can be kept as "clean" as possible. For instance, you might have a function that builds a table from a supplied 2-D array, also taking another 1-D array parameter for the column headings, and an optional argument for additional table tag attributes. Then in the view, all you might have to call is:

                    <p>blah blah blah</p>
                    <?php echo HTMLHelper::createTable($data, $headings, "class='pretty_table' id='fubar'"); ?>
                    </p>yadda yadda ydadda</p>
                    

                      FYI: FOrgive spelling mistakes, I'm on my phone.

                      I'd just like to chime in on the ZF aspect of things. The Zend Framework is not a complete package like CI or CakePHP. Instead it gives you the fundamental tools to create something like CI or Cake.

                      The ZF has the ability to use Smarty; however, there really isn't a need. It has it's own view handlers to display any output you want.

                      Take a look at Magento to see a fully fledged e-commerce app built on ZF that doesn't use smarty but is still relatively fast. I've been a ZF fan for a while and am trying to get a use-case scenario worked up for work in an effort to get us to convert from Cake.

                      I'm also of the camp that you don't need a "templating" engine since simple views would suffice.

                        bpat1434 and NogDog,

                        Well, I can see I am getting ahead of myself (AGAIN) as a lot of what everyone is saying is really Greek to me?!

                        I did some research last night on Frameworks, and it seems like that topic is a real religious battlefield. It sounds like Zend and Smarty are in different categories from "Frameworks" as well.

                        Because I am just in Chapter 2, I have no clue what the implementation of the MVC model will look like. In fact, I barely know what a PHP implementation is supposed to look like as I've barely done any coding yet! â­•o

                        I just to always be looking far ahead and make sound decisions before I invest lots of time in a lame approach. (One has to be careful trusting authors in books!)

                        Since this author sounds like he really knows his stuff, I'll just trust him and use his code and Smarty for now. And if I ever get a site built, then I can go back and improve it whether that means using OOP or a Framework or whatever else.

                        I'd just like to chime in on the ZF aspect of things. The Zend Framework is not a complete package like CI or CakePHP. Instead it gives you the fundamental tools to create something like CI or Cake.

                        Okay.

                        The ZF has the ability to use Smarty; however, there really isn't a need. It has it's own view handlers to display any output you want.

                        Okay.

                        Take a look at Magento to see a fully fledged e-commerce app built on ZF that doesn't use smarty but is still relatively fast.

                        Yah, I've heard Magento is pretty awesome. I have not looked at it so far because I want to build my own home-grown e-commerce site and learn how to do it myself before I go cheat with something like osCommerce or Magento. (I'm of the school that says "To really learn you have to screw up and learn how NOT to do things as well as how to do things. Hacking other people's code doesn't create guru programmers.)

                        I'm also of the camp that you don't need a "templating" engine since simple views would suffice.

                        Okay, good to know.

                        Thanks for the help, guys.

                        Amy

                          Heh...programmers can get into religious arguments about which framework to use (or none at all), which template to use (or none at all), which patterns to use (or none at all) just like computer users can get into religious arguments about Windows versus Mac versus Linux or iPhone versus Blackberry versus why-do-you-really-need-a-mobile-phone advocates. 🙂

                            NogDog;10925116 wrote:

                            Heh...programmers can get into religious arguments about which framework to use (or none at all), which template to use (or none at all), which patterns to use (or none at all) just like computer users can get into religious arguments about Windows versus Mac versus Linux or iPhone versus Blackberry versus why-do-you-really-need-a-mobile-phone advocates. 🙂

                            I completely agree with this. I have been working with somone elses MVC framework today and it was a nightmare to use. It was overly complex even to the user via the admin login.

                            Theres no real wrong answer just personal preference. If it works for its purpose and is easily scalable it's all the really matters. A client really isnt going to care whats behind it as long as it does the job.

                              Write a Reply...