Projects / Smarty PHP template engine

Smarty PHP template engine

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic, and is separated from the presentation. The Smarty design was largely driven by these goals: clean separation of presentation from application code; a PHP backend and Smarty template frontend; compliment PHP, not replace it; fast development/deployment for programmers and designers; quick and easy to maintain; a syntax that is easy to understand, with no PHP knowledge required; flexibility for custom development; and security (insulation from PHP).


Recent releases

  •  06 Dec 2010 17:50

    Release Notes: Smarty 3, a completely new code base since Smarty 2, features Template Inheritance, all new compiler/tokenizer, optimization for PHP 5, and more.

    •  14 May 2009 07:45

      Release Notes: This release strips backticks from {math} equations, throws an error when a template exists but is not readable, works around a bug in some versions of PCRE, fixes a function injection security hole, fixes pass expiration time in the cache_handler_fuc call in core.write_cache_file.php, and updates compiler.class.php to allow method chaining for PHP 4 and PHP 5.

      •  20 Oct 2005 11:02

        No changes have been submitted for this release.

        •  23 Mar 2005 17:59

          Release Notes: A vulnerability in the regex_replace modifier has been fixed that allowed PHP code to be executed from a template, even with template security enabled. If you are using template security features, it is highly recommended to upgrade, or at least replace the modifier plugin. A problem with the {strip}{/strip} tag (that was introduced in 2.6.7) has been fixed. Casting objects to arrays in the {foreach} "item" attribute has been addressed.

          •  02 Nov 2004 11:29

            Release Notes: This release is focused on minor fixes. The "core" directory has been renamed to "internals", so be sure to do a clean re-install and clear the compile/cache files if upgrading.

            Recent comments

            07 Sep 2008 02:15 mohrt

            25 Sep 2007 22:06 di11rod

            Re: What actual benefit do I get?
            I can't believe the negativity people have posted about this clever development package. For starters, it's plain rude for someone to step up and criticize people who put their own time, energy, and money into making something for others to use for free. If you think the engineering behind it is flawed, recommend improvements, fix the code yourself, or just move along to a better project. Show a little sensitivity towards the people who got off their as$es and did something for the community.

            Secondly, I have to back leeds on the performance impact of dual-layered interpretation. Anyone faulting a publishing environment for this is speaking from an academic perspective rather than years-in-the-trenches experience. Believe me. I used to travel around the country auditing web site performance and this ain't something to be worried about. Bigger performance issues can be found by:
            1. Configure memory caching for Apache.
            2. Turn off logging or set it up on a different device (not network-mounted, either).
            3. Tune your DB. Make sure common SQL queries are set up as stored procedures. Make sure indexes are configured properly. Make sure none of your code hits the DB unnecessarily. Nested for-loops making calls to the DB for each row returned in the parent loop is a horrible drag.Oh, well. Smarty looks cool to me.Seth

            19 Sep 2007 12:43 mohrt

            Re: What actual benefit do I get?
            Instead of regurgitating explanations here, read the "Right for me" and "Why use it" links from the Smarty home page. That should tell you plenty, and you can make an informed decision if Smarty is a good choice for your application. It isn't meant to be the be-all end-all template toolkit for PHP, it is just another tool in the toolbox.

            > Hi there.


            > I testet Smarty and had a look at the

            > documentation. Now, however, there

            > remain some questions.


            > The syntax within Smarty templates is

            > similar to the common PHP syntax. I

            > output a variable using the notation

            > {$MyVar} - in a PHP script, I would

            > write <?=$MyVar?>. Then I have

            > modifiers and plugins like

            > "upper" doing tasks that are

            > already covered by native PHP funktions

            > (e/g strtoupper()) - yet the Smarty

            > stuff is less flexible in use (and

            > probably slower since PHP functions are

            > called via the "template engine

            > detour"). All in all, any template

            > designer will have to dig into the

            > Smarty syntax and learn it before they

            > can create working templates.


            > If I got it right, the compilation of

            > templates means that files are

            > translated from the "Smarty

            > language" to PHP, meaning of course

            > that these compiled scripts will be

            > parsed again by the PHP parser on

            > request.

            > Nothing against that - but when the

            > syntax is so similar, why do we need the

            > Smarty templates in the first place?

            > So from my point of view this template

            > engine just looks a little like a big

            > wrapper that does things you could do

            > with plain PHP - and yet it is not much

            > easier to use than PHP itself.


            > With those drawbacks - tpl designer

            > having to learn a "language"

            > similar to real scripting, a lot of

            > overhead code on every request and

            > nothing really you couldn't achieve with

            > plain PHP code just as easily - what do

            > I get out of using Smarty?

            19 Sep 2007 12:36 mohrt

            20 Jun 2007 22:32 marionconsulting

            Re: design problem with smarty

            > while using php we can show various

            > category name rowwise with more than one

            > column in each row.


            > like: using while loop with

            > mysql_fetch_array()

            > we can loop the result.

            > within the loop if we use

            > mysql_fetch_array()

            > again, then the pointer jumps to

            > next record.


            > I found it impossible using smarty. We

            > cant go to next record within any loop.

            > For this purpose we have to make static

            > pages while it can be made dynamic if

            > written in raw php.


            > if anybody faced this problem and has a

            > solution pls reply.

            Smarty can definitely handle the situation. Pleaes provide code and an example of exactly what you want to do and I'll show you how to do it in Smarty.


            Project Spotlight


            A Fluent OpenStack client API for Java.


            Project Spotlight

            TurnKey TWiki Appliance

            A TWiki appliance that is easy to use and lightweight.