Discover and share the best of the web!
Learn more about Digg by taking the tour.
Top 25 PHP template engines
whenpenguinsattack.com — The top 25 PHP template engines. My personal favorite is Smarty.
- 1284 diggs
- digg it
- morganm, on 10/12/2007, -4/+10Everybody seems to love Smarty but me. I've got two sites running it, or rather walking it, it's ridiculously slow and a new syntax to learn, with a bunch of analogs for existing PHP functions. I am not a fan, but I suppose they just could have been poorly implemented in my sites.
It also always seems like I'm digging deep into nested directories to find the actual page content to edit.- vostok4, on 10/12/2007, -1/+4Heh, I hate it too. I'd love to see a site getting > 10000 hits a day use smarty, then implement that same site in a more efficient manner and watch the load go doooown.
- form3hide, on 10/12/2007, -2/+5We're (songmeanings.net) using Smarty and we get well over the above mentioned stat. I love it -- very flexible, but I've noticed that it does lag if it's not implemented efficiently. But then again, any code that's not efficient is going to cause problems.
- form3hide, on 10/12/2007, -15/+1Oops, sorry -- went to edit and messed things up. Sorry.
- pumacub, on 10/12/2007, -58/+4Ugh... PHP is like drug abuse, you don't realize how much it ruins your life until you find help. =P
Seriously, PHP is garbage, great for newbies though. =) - metalhed, on 10/12/2007, -1/+25@pumacub:
You know Digg uses PHP, right? - ileadyouth, on 10/12/2007, -2/+10RE: pumacub
Mind backing up your ignorance...er...um....knowledge with something besides your opinion that no one cares about? - SamKellett, on 10/12/2007, -1/+12@vostok4 and pumacub:
Flickr uses both PHP and Smarty - ziemkowski, on 10/12/2007, -0/+2Smarty is extremely fast _if_ you compile the templates and use an accelerator. If you don't do both (or worse, neither), it's going to be slow and Smarty then may not be the best option for you.
- coolbru, on 10/12/2007, -0/+1Yahoo uses Smarty and PHP too, not exclusively though.
- sembetu, on 10/12/2007, -0/+1@pumacub: what do you use that is better?
thanks - NumbCore, on 10/12/2007, -0/+1@ form3hide:
I like the site and the idea, but songmeanings.net is slower than molasses on a cold day in antarctica. - iamcam, on 10/12/2007, -0/+1I use SMARTY on a few sites. Simply turning caching on will significantly speed-up you site, especially as you realize you can output the cached page and quit script execution within the first few lines of code, thus skipping the remainder of the business logic.
- cviebrock, on 10/12/2007, -0/+0vostok4: www.tucows.com uses Smarty. Runs just fine. 1000000+ visits a day.
- jellygraph, on 10/12/2007, -0/+2@pumacub:
pumacub probably loves java... certainly sounds like one of them...
and java developers make crap PHP developers, because most java newbies have got a small mindset when it comes to developing applications...
Smarty _is_ slower, even if you design your site properly with it. I stayed far away from it and got on of my clients to get rid of it on their site, and they've been thanking me since.
Which is too bad, because its a great idea in principle. But just not in reality. - Obsidian743, on 10/12/2007, -1/+1The fact that there are 25 to choose from says a lot about PHP...and believe it or not it ain't good.
- dante2010, on 10/12/2007, -10/+1yaya i can digg it
- vostok4, on 10/12/2007, -2/+10http://www.duggmirror.com/programming/Top_25_PHP_template_engines/
BTW, #1:
body.tpl = HTML stuff with an <php echo $body; ?>
businesslogic.php = $body = 'garbage'; include('body.tpl');
OMGAH! It's a EFFICIENT TEMPLATING ENGINE!- wildleaf, on 10/12/2007, -0/+8I couldn't agree more. Business logic and display should be seperate. But what is the point of learning an additional language for templating when PHP is already that? You can you foreach loops inside tags just as clearly as you can code a weird HTML comment that gets parsed by an engine that adds latency. I have gone to using shorthand for echo statments though. Makes it feel more templatey
< ?= $body ?> - xenoguy, on 10/12/2007, -1/+4it obviously has its applications.
if your designers know PHP, thats great, work in PHP.
but if youre trying to build a large scale project, and you have programmers working on complex internals, you dont want the programmers breaking the design, and the designers breaking the code. - wildleaf, on 10/12/2007, -1/+4So instead of teaching them minor PHP (such as simple loops and how to print out variables with a $ in front of them) you will tell them to put in a specially formatted HTML comment or some sort of ##VARIABLETOPRINT## that they will paste all over the place. How is ANY templating language ANY easier than basic template based PHP?
Keep the template and the busieness logic seperate. Dont turn designers into programmers, but for goodness sake - listen to the argument. - patmfitz, on 10/12/2007, -0/+4"How is ANY templating language ANY easier than basic template based PHP?"
If you're designing a template for your own app, use PHP.
But if you want users to make their own templates, you can't allow arbitrary PHP in the templates because it's a huge security hole. In a case like that you'll have to use a template engine that restricts what the user can do.
For example: I make a template in Wordpress and distribute it in the wild. People who like the template install it on their blogs. Unknown to them, the template sends their username and password to my server, and I add spam pages to their blog, back-dated so they never even notice them. - wildleaf, on 10/12/2007, -0/+3I agree with your point concerning security. I completely understand the argument for templating engines in these situations. I need to remember that not everyone inspects what code they implement.
I guess I have been fighting for the last few years for internal apps to use PHP as a "templating engine" and lost track of other implementations in the wild web. I still think that PHP should be the only templating engine you need for internal development. - phpwebdev, on 10/12/2007, -1/+0what u mean about dynamic section
foreach , section . .... on more about AJAX integration (http://zephyr-php.sourceforge.net/)
I'm use smarty from 4 years . and remember what was old version - too slow, problem with cache ...
But now smarty is my best engine (more 50 sites now is on line with smarty )
- wildleaf, on 10/12/2007, -0/+8I couldn't agree more. Business logic and display should be seperate. But what is the point of learning an additional language for templating when PHP is already that? You can you foreach loops inside tags just as clearly as you can code a weird HTML comment that gets parsed by an engine that adds latency. I have gone to using shorthand for echo statments though. Makes it feel more templatey
- crilen007, on 10/12/2007, -12/+4http://www.duggmirror.com/programming/Top_25_PHP_template_engines/
Won't work too well due to PHP though =(- gweedo767, on 10/12/2007, -1/+5Okay, while duggmirror is nice and all, why do we post links to it on a story that is taking the load just fine?
- crilen007, on 10/12/2007, -4/+6Because it errored for me twice already.
- gweedo767, on 10/12/2007, -0/+5I personally have really fallen in love with Smarty. We just completed a complete redesign/reworking of www.cspost.com and it was my first production site with Smarty. It is very easy and it is nice to have your Presentation and Logic separated very cleanly.
- gdonald, on 11/13/2007, -3/+7My favorite PHP template engine is eval(). Anything else is baggage.
Smarty... pffft. - munkt0n, on 10/12/2007, -0/+1I'm still using the template engine in phplib
- ziemkowski, on 10/12/2007, -0/+0phplib has huge problems growing to handle traffic though. We switched from phplib to smarty and found not only huge performance gains, but that our development team was writing better code with less oversight... the biggest improvement was moving from a push to pull system that responded to data rather than having to be managed by another layer of PHP code. The parsing mechanism in phplib, besides for being slow, ate up gobs of memory.
The nice thing with a compiled Smarty template, is that it's just a regular HTML+PHP file that can be tokenized by an accelerator and stored in shared memory, making it extremely fast after the first parse.
- ziemkowski, on 10/12/2007, -0/+0phplib has huge problems growing to handle traffic though. We switched from phplib to smarty and found not only huge performance gains, but that our development team was writing better code with less oversight... the biggest improvement was moving from a push to pull system that responded to data rather than having to be managed by another layer of PHP code. The parsing mechanism in phplib, besides for being slow, ate up gobs of memory.
- doubledoh, on 11/13/2007, -1/+13php IS a template engine (amoung other things). Why use a middle man?
- TheCookieMaker, on 10/12/2007, -1/+1some people don't know much about programming php and working with a template gives them a chance to stick their feet in the water before they dive in.
- misterjangles, on 10/12/2007, -0/+3Well, even though PHP is, in a way, a template engine of sorts that doesn't mean you can't still follow some good practices for scalable design.
If you have graphic designers who work on html and you don't want them mucking around in your php code, that's a good reason. If you want to make a skinable site, that's another reason. If you just want to separate the html from the php logic code, that's a reason too.
Smarty brings with it some extra degree of complexity. So if your project is really basic, then you may just create more pain for yourself. But if your project is large and complicated, then the overhead of using Smarty can pay off and make your life easier. - addw, on 10/12/2007, -0/+0Don't forget that templating helps reuse of php code. Eg: you write a login module, with a small amount of parameterisation you can use it for a different department/customer/... but it will still look similar. Use it with a templating front end you can make it look very different (== happy customers) by supplying a different set of templates. You find a bug in your login code - fix it once and all uses are fixed.
I have done exactly this using smarty -- very nice.
- lowter, on 10/12/2007, -1/+1I typically use a personal variant of Savant.
All of the other templating engines are too complex overall, and I find just harder to work with. - chadu, on 10/12/2007, -0/+1anyone out there using a template engine and CakePHP? Would like to hear a few good suggestions on this, and is it really even necessary with a framework?
Thanks.- jiminoc, on 10/12/2007, -0/+4you don't need a template engine with Cake....
just pepper in PHP code in your view page. template engines are so 2001. - chadu, on 10/12/2007, -0/+1jiminoc, thanks for the confirmation... was thinking this was the case. I appreciate it.
- joelhardi, on 10/12/2007, -0/+1Yeah, all these crappy template languages are a solution looking for a problem, just developers scratching an itch.
I would love to never have to learn another one, but instead every CMS developer has to invent a half-declarative, half-functional templating language that winds up taking acres of time even for developers to learn -- let alone the graphic designers and other folk these templating languages are supposed to be dumbed down for. And your typical HTML-savvy designer would *much* rather pick up a some inline PHP skills to put on the resume than learn some obscure templating pseudocode.
- jiminoc, on 10/12/2007, -0/+4you don't need a template engine with Cake....
- percussionlab, on 10/12/2007, -2/+4Awfully ignorant question - what is a PHP Template for? I tried to google the term, but no definitions appeared, only solutions. Thanks for not flaming me in advance and any info you throw my way! :)
- putamare, on 10/12/2007, -0/+2http://www.nyphp.org/content/presentations/3templates/
- comart, on 10/12/2007, -5/+0I used to use a simple template.
Just inject (replace) your code into a signature on the template.
PHP rocks !
read more...
http://dholes.pxax.com/ - kalmi, on 10/12/2007, -0/+3Does digg use any template engine?
- mike503, on 10/12/2007, -0/+2first, PHP rocks.
second, I prefer something more standard like XSL/XML transforms. you'll incur a higher processing cost, but there are appliances to offload it (ZXTM - software, Sarvega appliances - hardware), caching techniques, and always just scaling up/out if needed.
no need to learn *proprietary* templating languages. it's a w3c documented standard (as much so as CSS, HTML, etc...) and keeps the data and presentation/business logic completely separate as well. I've created my own little engines in the past, and it always winds up being a "hack" of just recreating blocks for each page segment or looping segment, string replacements, etc.
however I am looking at some sort of AJAX-related style of coding and offloading the template work to the client, with heavy dependency on CSS (since a JSON/AJAX driven page would mainly be div tags and doing injections or just raw XML/JSON data out and having the user's browser do the work anyway.) - jiminoc, on 10/12/2007, -1/+5smarty is horrid. It's a template language built on a template language. None of the new frameworks are using a traditional template system because we've all learned from the past. There is nothing wrong with peppering PHP code in your VIEW scripts. Zend, CakePHP, etc all follow this style. Smarty is a bloated mess.
- ManInPants, on 10/12/2007, -0/+1Kewl the way the php simulates a 500 server error! Looks authentic.
- EggzDiggs, on 10/12/2007, -0/+1My senior developer asked me to learn and use Smarty for a large scale project. I'm interested to see how the caching speeds up (or slows down a/c to some above posts) the site.
- evileddie, on 10/12/2007, -1/+1Here's a good review of some template systems for php
http://www.zend.com/zend/trick/tricks-nov-2001.php- guice, on 10/12/2007, -0/+2Small list and outdated. Template Engines have changed greatly in the past 5 years. Especially with the release of PHP5.
- guice, on 10/12/2007, -0/+2I digg the list, although there is little point of building a template engine on top of a template language. I appreciate ones like Savant more, although now I use Frameworks which make good use of PHP as the "template language" instead of their own wrapper recreation.
As been stated over and over again, Smarty is bloated and completely pointless. Without it's "compile" ability (which merely just converts your Smarty code to PHP code), it would be the slowest template engine around. - whackaxe, on 10/12/2007, -0/+2PHP IS a template engine. not as clean and easy as smarty for example, but if you plan your app right, it'll be the best solution
- isleshocky77, on 10/12/2007, -0/+1Does anyone have a link to a review or list of Top X PHP frameworks. I've just begun to look into frameworks I'm trying to decide on which would be best for me. Thanks in advance.
- wildleaf, on 10/12/2007, -0/+3If you are looking at anything besides symfony http://www.symfony-project.com/ if you have PHP 5, or CakePHP http://www.cakephp.org/ if you have PHP4, then you are wasting your time. I would also REALLY suggest looking at Ruby on Rails http://www.rubyonrails.org or Django http://www.djangoproject.com/ if you are able to step away from PHP and look at other languages. Afterall - the programming language is rather a light sprinkling when you look at using frameworks anyway.
- plimpton, on 10/12/2007, -0/+0Currently I use Etelos http://www.etelos.com and it works well for what we do. You should check it out
- plimpton, on 10/12/2007, -0/+0not only does it handle templating, but everything relating to your site, table manipulations, file handling, php, java and .net code is available to use also. With the limited resources we have, there's no way we would have been able to do what we do without it
- Negligence, on 10/12/2007, -0/+0In my opinion, templates should be not used unless absolutely necessary, or at least until the overhead of loading the template engine is removed.
Remember folks, you're loading 100kb+ in files (like in Smarty) everytime a page is loaded just for your code to run. That is not including content. And processing resources. It is just pure bulk.
If template engines in PHP were a 'load-once' thing, then they would be considerably more applicable. For the rest of us performance-minded individuals who have to upkeep an acceptable standard of speed and minimize bandwidth and resources, template engines simply do not fit into the puzzle. At least such has been the case in my world of development.- guice, on 10/12/2007, -0/+0You obviously don't understand the reason for templates, nor do you understand their logic if you think they all run like Smarty. Smarty is considered bloated not just because it is, but also cause of all the extra crap it does to finally display the page.
- vh1`, on 10/12/2007, -0/+1I personally hate smarty. as others have said, it's just learning a new syntax that only has one implementation
the best "theme engine" I've used is one that was released on a mailing list, which used XSL for the themes. it was quick, and XSL/XPATH is easy to learn and has many applications- echophp, on 02/07/2008, -0/+0that is true , i agree with you
Update your knowledge in the world of web programming with the latest updated .
http://www.websitescript.blogspot.com
http://www.echophp.tk
- echophp, on 02/07/2008, -0/+0that is true , i agree with you
- mutant, on 10/12/2007, -0/+1No Pattemplate? WTF?
http://www.php-tools.de/ - fenris6644, on 10/12/2007, -0/+1I'm all for choice but does anyone else find it absurd that PHP actually has over 25 templating engines? Some of these folks need to get together and find a common ground so that more energy can be spent on building a world-class solution instead of reinventing the same wheel over and over.
- Vapid, on 10/12/2007, -0/+2Just use PHP templating. PHP is a templating language in itself. Why build a templating language on top of one that already exists? I use smarty in several areas and there are close to no reasons to use it. If you like the caching in Smarty, I strongly recommend you use memcache or a real php extension built for this purpose. Combine this with an accelerator and optimizer and you're good to go.
As far as Smarty as a templating engine, I fail to see how these two differ:
With Smarty:
businesslogic.php = Contains all PHP code. $tpl->assign('var', 'value);
body.tpl = HTML code with smarty tags. Hello {$var}!
Without Smarty:
businesslogic.php = Contains all PHP code. $var = 'value'; include 'templates/body.php';
body.php (or another extension) = HTML code with php. <?=$var>.
This completely removes the necessity of a templating engine. PHP already has one. Smarty is for noobs.- phpwebdev, on 10/12/2007, -1/+0@Vapid
go here http://www.phpinsider.com/smarty-forum/ and say that
"This completely removes the necessity of a templating engine. PHP already has one. Smarty is for noobs."
- phpwebdev, on 10/12/2007, -1/+0@Vapid
- jellygraph, on 10/12/2007, -0/+1Here's a good template engine. Just ask your non-technical guys to design the page in HTML how it ought to look like, then pass on that HTML template to the developers, along with documentation on how the underlying code should work, and voila. It's just as fast and faster for the server, more scalable, and simpler to manage afterwards
again, I'll emphasize: [[simpler to manage afterwards]] - ThaLyric, on 10/12/2007, -0/+1well .. I don't like Smarty. I use XTemplate (http://www.phpxtemplate.org/).
@Vapid. I use a template engine such as Smarty yet I'm not a noob. The main advantage is with template engines is that I can separate logic from design. Wat my office I ussually work with an other html dude. He doesn't know any thing about PHP. So ... when he sees - tasol, on 10/12/2007, -0/+0good
- ThaLyric, on 10/12/2007, -0/+1hmmm my post just got ***** up ...
What I'm tried to say is that I can develop with the same template block definitions (wich I created) as the HTML dude. The HTML dude will not see the php code, he can just focus on html codes he knows. When he's done with his html template, I can just use his template with my code. Just as long he will follow my block-definitions , everything in that block he can design a lot's of things, just don't ***** up my block-definitions. By the way a block definition goes something like
<!--
this is something he can remember, cuz is like HTML comments ;-)- rense, on 10/12/2007, -0/+1You gotta use html entities here, mate ;)
- ThaLyric, on 10/12/2007, -0/+1<!-- BEGIN: myblock -->
<!-- END: myblock --> - Leech, on 10/12/2007, -0/+1tinybutstrong is awesome.. period.
- derianto, on 10/10/2007, -0/+0The list of those many template engines inspired me to think whether it is possible for designers to write all flow-controlling scripts in English instead of in any weird scripting languages, and it actually is. http://derianto.blogspot.com/2007/08/php-templating-solution-without-php.html
- echophp, on 02/07/2008, -0/+0This is a great article keep it up.You really make a real research . i will be expecting more of it. Thanks
Update your knowledge in the world of web programming with the latest updated .
http://www.websitescript.blogspot.com
http://www.echophp.tk - Franck911, on 09/15/2008, -0/+0A lot of people seem to dislike smarty templates engine.
Let me clear some points:
- all template passed by smarty are compile to file with php code so page become faster as a 'php template'
- smarty have cache system that is very customizable
- smarty templates preview can be view directly without php
- smarty templates have more readability than php based template
- learn syntax take about only 1 hour
- php based template don't separate completly the logic and view. you always to switch to php to html html code... . It doesn't help maintenance when you have big page
- designers don't need to learn php
- you can compressed Smarty file: Smarty.class.php (62ko to 29ko) and Smarty_Compiler.class.php(91ko to 54ko), so when you don't need to re-compile template, smarty libs is only about 30ko to load
- most of plugins are loading on demand and is very very easy to create new one!
- morganm say: I've got two sites running it, or rather walking it, it's ridiculously slow and a new syntax to learn, with a bunch of analogs for existing PHP functions. I am not a fan, but I suppose they just could have been poorly implemented in my sites.
> lol he anwser itself at his problem. Poor implementation mean poor perfomance and its same for everything in php.
> Good implementation, compressed main smarty files in conjunction with cache system activated do a kick ass job with a very decent good speed!
Digg is coming to a city (and computer) near you! Check out all the details on our