fmII
Fri, Aug 29th home | browse | articles | contact | chat | submit | faq | newsletter | about | stats | scoop 04:24 UTC
in
Section
login «
register «
recover password «
[Project] add release | add branch | add screenshot | broken links | change owner | email subscribers | update project | update branch (urls) [Project]

 Smarty PHP template engine - Default branch
Sections: Handhelds, Mac OS X, Unix

 

Added: Sat, Jan 20th 2001 11:35 UTC (7 years, 7 months ago) Updated: Wed, Sep 19th 2007 14:34 UTC (11 months, 15 days ago)


About:
Although Smarty is known as a "Template Engine", it would be more accurately described as a "Template/Presentation Framework." That is, it provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application. Smarty is not a simple tag-replacing template engine. Although it can be used for such a simple purpose, its focus is on quick and painless development and deployment of your application while maintaining high performance, scalability, security, and future growth.

Author:
Monte Ohrt, Andrei Zmievski <monte __at__ ispi __dot__ net, andrei __at__ ispi __dot__ net> [contact developer]

Rating:
8.37/10.00 (47 votes)

Homepage:
http://smarty.php.net/
Tar/GZ:
http://smarty.php.net/[..]d.php?download_file=Smarty-2.6.10.tar.gz
Changelog:
http://smarty.php.net/changelog.php
CVS tree (cvsweb):
http://cvs.php.net/cvs.php/smarty
Mailing list archive:
http://marc.theaimsgroup.com/?l=smarty&r=1&w=2

Trove categories: [change]
[Development Status]  5 - Production/Stable
[Intended Audience]  Developers
[License]  OSI Approved :: GNU General Public License (GPL), OSI Approved :: GNU Lesser General Public License (LGPL)
[Programming Language]  PHP
[Topic]  Software Development

Dependencies: [change]
No dependencies filed

 
Project admins: [change]
» Monte Ohrt (Owner)

» Rating: 8.37/10.00 (Rank 331)
» Vitality: 0.02% (Rank 3052)
» Popularity: 12.89% (Rank 135)

project statsdownload stats
(click to enlarge graphs)
   Record hits: 108,026
   URL hits: 52,777
   Subscribers: 391

Projects depending on this project:
phpBuns
Control Framework for PHP
eXtreme Project Management Tool
SmartyX
phpTimeSheet
(Note: 26 projects depend on this one. The ones displayed are picked by a randomizer.)


Other projects from the same categories:
Karibou
Advanced Website Creator
Gnome Moleskine
svn-install
Dir::List

Users who subscribed to this project also subscribed to:
mysqmail-postfix-logger
foocache
eGroupWare
Ampoliros
AsciiDoc


Add comment · Rate this project · Subscribe to new releases · Ignore this project · Email this project to a friend · Project record in XML

 Branches

Branch Version Last release License URLs
Default 2.6.10 20-Oct-2005 GNU Lesser General Public License (LGPL) Homepage Tar/GZ Changelog

 Articles referencing this project

 Comments

[»] design problem with smarty
by dyuti_leo - May 2nd 2006 00:33:07

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.

[reply] [top]


    [»] Re: design problem with smarty
    by endless552001 - Mar 14th 2007 06:51:21

    Smarty can use foreach within foreach like below. {foreach from=$sample item=test} {foreach from=$test item=item} {$item.value} {/foreach} {/foreach}

    [reply] [top]


    [»] Re: design problem with smarty
    by marionconsulting - Jun 20th 2007 22:32:53


    > 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.

    --
    www.marionweb.com Expert web development specializing in PHP, Smarty, MySQL, Apache, LAMP.

    [reply] [top]


[»] What a bad idea
by Jeremy - Mar 30th 2006 12:52:44

Smarty is quite possibly the worst idea for a template engine I have ever seen. It says in their documentation that it makes it so that web page designers do not have to deal with PHP code syntax, but instead an easy-to-use templating syntax not much different than plain HTML (http://smarty.php.net/rightforme.php). Consider the following Smary “Code”

{if $smarty.session.user and ( $user_type eq "editor" or $user_type eq "admin" )}
<input type=checkbox name=edit value="y"> edit <br>
{/if}

That looks a lot like a programming language to me, and Smarty is nothing like HTML. It is just another programming language with HTML embedded into it just like PHP. If the designer has to learn how to program anyways why not just use PHP? Now if a PHP programmer ever has to change something in the presentation layer he has to learn a new language. It’s kind of like writing a windows program in C# then using VB for the presentation layer. There really isn’t anything wrong with it but there is no point either, why not just write the whole thing in C#? That would save the trouble of learning 2 languages for no reason. Smarty is just a big waste of time and resources.

--
Jeremy

[reply] [top]


    [»] Re: What a bad idea
    by Monte Ohrt - Sep 19th 2007 12:36:24

    You obviously haven't used Smarty if you think it's sole purpose is an alternative syntax for template designers. That is a very small part of it, and more of a side-effect than a purposed feature.


    > Smarty is quite possibly the worst idea

    > for a template engine I have ever seen.

    > It says in their documentation that it

    > makes it so that web page designers do

    > not have to deal with PHP code syntax,

    > but instead an easy-to-use templating

    > syntax not much different than plain

    > HTML

    > (http://smarty.php.net/rightforme.php).

    > Consider the following Smary “Code”

    >

    > {if $smarty.session.user and (

    > $user_type eq "editor" or

    > $user_type eq "admin" )}

    > <input type=checkbox name=edit

    > value="y"> edit <br>

    > {/if}

    >

    > That looks a lot like a programming

    > language to me, and Smarty is nothing

    > like HTML. It is just another

    > programming language with HTML embedded

    > into it just like PHP. If the designer

    > has to learn how to program anyways why

    > not just use PHP? Now if a PHP

    > programmer ever has to change something

    > in the presentation layer he has to

    > learn a new language. It’s kind of like

    > writing a windows program in C# then

    > using VB for the presentation layer.

    > There really isn’t anything wrong with

    > it but there is no point either, why not

    > just write the whole thing in C#? That

    > would save the trouble of learning 2

    > languages for no reason. Smarty is just

    > a big waste of time and resources.

    >

    [reply] [top]


[»] What actual benefit do I get?
by streetjesus - Jun 8th 2002 06:33:17

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?

[reply] [top]


    [»] Re: What actual benefit do I get?
    by Yaro - Jul 6th 2002 21:26:24


    > 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?

    You even get no close to the idea and technology of Smarty. Smarty doesn't parse already compiled scripts! They are pure PHP which executed as fast as other PHP scripts. So Smarty syntax give you a Power of flexibility, whean you want to make "every day task" in one line of template code. Smarty is the best thing which I use in my projects.

    [reply] [top]


    [»] Re: What actual benefit do I get?
    by Monte Ohrt - Jul 11th 2002 18:01:38


    > 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?


    The benefits are countless, but one good point is the separation of application logic from presentation logic. The application programmer can change application logic without worrying about messing up the presentation of content, and a template designer can modify the presentation without breaking application logic.

    [reply] [top]


    [»] Re: What actual benefit do I get?
    by Tim - Sep 30th 2002 08:17:56

    Hi, The benefits of using smarty are that you get a *structured* system for templating that is standardised. If you use PHP, you still need to develop your own system for including sub elements and setting variable scope and you also end up with having to use <?php print 'web design leeds; ?> when you want to include small sections. This would be a lot cleaner if it is set inside the php and included in the page as a variable {$webAddress}. On top of this the argument about speed is a stupid one that most people really need to get their heads around. we are talking milliseconds for page build when the average delivery time is seconds. Thats a 1000x difference. Even if you are running a VERY busy site, you are unlikely to get more than 10 simultaneous hits on your server at once. This means that at the worst your pages will be maybe 0.2s slower through the use of templating and typically about 0.02s. As an example of speed, our website www.pollenation.net is built using smarty and we've tested it at 100 hits per second and it handles it fine. And this is with mod rewrite overhead and an application server in front of it and database abstraction etc etc.

    --
    web design leeds

    [reply] [top]


      [»] Re: What actual benefit do I get?
      by di11rod - Sep 25th 2007 22:06:26

      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

      [reply] [top]


    [»] Re: What actual benefit do I get?
    by Brian Takita - Oct 26th 2002 20:18:27

    Hello,

    I have a project named PHP Object Oriented Framework.

    POOF uses PHP itself as its template engine. Nested templates are also easily supported. Using PHP as the template language means there is very little script overhead and no compilation is necessary. POOF is still in alpha stage however.

    However the template syntax might be harder to use for template designers.

    What do you all think about having PHP as the template language?

    Sincerely,
    Brian Takita

    [reply] [top]


    [»] Re: What actual benefit do I get?
    by Monte Ohrt - Apr 15th 2003 07:46:59


    > 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?


    This is a fairly good explanation to your questions:


    http://smarty.php.net/whyuse.php

    [reply] [top]


    [»] Re: What actual benefit do I get?
    by Monte Ohrt - Sep 19th 2007 12:43:09

    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?

    [reply] [top]


[»] Poor Performance
by August - Jan 26th 2001 21:00:08

Did a quick benchmark of Smarty vs phplibs templating. On a simple test of a 3 variable block of code repeated 20 times Smarty served 65 page/s with compile_check = true and 80 with compile_check = false.

phplib on the other hand served 90 pages/s at all times. Not sure why this is.

[reply] [top]


    [»] Re: Poor Performance
    by Monte Ohrt - Jan 31st 2001 16:25:13


    > Did a quick benchmark of Smarty vs
    > phplibs templating. On a simple test of
    > a 3 variable block of code repeated 20
    > times Smarty served 65 page/s with
    > compile_check = true and 80 with
    > compile_check = false.
    >
    > phplib on the other hand served 90
    > pages/s at all times. Not sure why this
    > is.
    The performance problem you are seeing here is the overhead of PHP compiling the op-tree for the PHP scripts on each request. Smarty is a more complex templating engine than phplib (and probably most others), therefore it has more code for PHP to compile on each invocation. If you do some benchmark tests using a PHP cache solution, such as Zend cache or APC, you will see that Smarty runs at least as fast, but most likely faster than conventional template solutions since there is no template parsing overhead. See the smarty mailing list archive for more a more detailed discussion of this very subject.

    [reply] [top]


    [»] Re: Poor Performance
    by Monte Ohrt - Mar 7th 2001 20:41:07

    FYI, version 1.3.1 has some good speed improvements by narrowing the amount of code PHP must compile after the initial template compilation.

    [reply] [top]


      [»] Re: Poor Performance
      by Brent R. Matzelle - Aug 14th 2001 09:26:41


      > FYI, version 1.3.1 has some good speed
      > improvements by narrowing the amount of
      > code PHP must compile after the initial
      > template compilation.

      I can attest to these speed improvements. I converted a single very complex page running on PHPLIB template with multiple set_block() and parse() calls to Smarty. The page came up much faster with Smarty and my code is much cleaner than before! Plus, I am successfully using Smarty along with APC for even more speed. This is a truly excellent product. I can also use it in commercial products because of the license. Not surprising but I am converting everything to Smarty.

      [reply] [top]


        [»] Re: Poor Performance
        by Monte Ohrt - Mar 20th 2002 18:26:23


        >
        > % FYI, version 1.3.1 has some good
        > speed
        > % improvements by narrowing the amount
        > of
        > % code PHP must compile after the
        > initial
        > % template compilation.
        >
        >
        > I can attest to these speed
        > improvements. I converted a single very
        > complex page running on PHPLIB template
        > with multiple set_block() and parse()
        > calls to Smarty. The page came up much
        > faster with Smarty and my code is much
        > cleaner than before! Plus, I am
        > successfully using Smarty along with APC
        > for even more speed. This is a truly
        > excellent product. I can also use it in
        > commercial products because of the
        > license. Not surprising but I am
        > converting everything to Smarty.

        The 2.0 release has _major_ speed improvements, and Smarty now has a benchmark page to compare for yourself.

        [reply] [top]


[»] Alternative
by deekayen - Jan 26th 2001 10:47:41

If you can't use this class, and you have access to the php.ini file, you might be able to still add the APC Alternative PHP Cache zend extension and use a different template class.

[reply] [top]


    [»] Re: Alternative
    by Monte Ohrt - Jan 31st 2001 16:35:24


    > If you can't use this class, and you
    > have access to the php.ini file, you
    > might be able to still add the APC
    > Alternative PHP Cache zend extension and
    > use a different template class.
    I think there is some confusion about what Smarty is. Smarty is not a PHP caching solution. Smarty is a template engine. APC will merely speed up compilation of the PHP scripts themselves, but nither is an alternative to the other. They actually work very well together.

    [reply] [top]


      [»] Re: Alternative
      by deekayen - Jan 31st 2001 17:01:52

      No, I'm not confused. I was just 1) plugging APC because I think it's cool and 2) letting people know about it because of people that can't use Smarty because it might not be a practical solution for them. I have nothing against Smarty.

      [reply] [top]


        [»] Re: Alternative
        by Andrei Zmievski - Feb 2nd 2001 15:11:04

        Plug APC all you want - it is cool, but apparently you have very little understanding of what Smarty is and what it does, because otherwise you would not have said what you have.

        [reply] [top]


          [»] Re: Alternative
          by deekayen - Feb 2nd 2001 23:01:43

          Fair enough. I'll admit I haven't downloaded Smarty, so I have said all of the previous without even having looked at the code.

          [reply] [top]


[»] Limitation of Smarty
by Haohoa - Jan 25th 2001 22:53:11

This cached template system for PHP is a very good idea, but it works only for directory trees that are owned by the user running Apache. It's totally useless for a Unix user publishing in its private public_html directory.

[reply] [top]


    [»] Re: Limitation of Smarty
    by Monte Ohrt - Jan 31st 2001 16:17:48


    > This cached template system for PHP is a
    > very good idea, but it works only for
    > directory trees that are owned by the
    > user running Apache. It's totally
    > useless for a Unix user publishing in
    > its private public_html directory.
    One workaround to this problem, you can create a world writable directory for the compiled templates (owned by yourself obviously), then once the templates are initially compiled, change it back to read-only. Smarty will no longer need to write more files there once the initial compile is complete.

    [reply] [top]




© Copyright 2008 SourceForge, Inc., All Rights Reserved.
About freshmeat.net •  Privacy Statement •  Terms of Use •  Trademark Guidelines •  Advertise •  Contact Us • 
ThinkGeek •  Slashdot  •  Linux.com •  SourceForge.net  •  Jobs