This way you get the benefits of both template tag syntax and the speed of PHP.Ĭompilation happens once when each template is first invoked, and then the compiled versions are used from that point forward. Under the hood, Smarty compiles copies of the templates as PHP scripts. The Crash Course section gives a good overview how Smarty is typically implemented in a PHP application. What does Smarty look like, and how do I use it?
The documentation does a good job of indicating what things to watch out for. injecting PHP in templates) will cause more problems than the presentation separation was meant to resolve. Numerous features are also available for presentation such as template inheritance, which maximizes template re-use and streamlines organization.Īlthough Smarty gives you the tools to make a clean separation of presentation from application code, it also gives you plenty of room to bend those rules. Smarty gives web designers exactly the tools they need, and gives developers fine-grained control over these tools. Designers would only need a small fraction of this manual, and it doesn't make it easier for them to find what they need.
The PHP manual is intended for developers. You could teach designers the rules of application design, but this should be unnecessary (now they are developers!).
PHP makes it too easy to add code into templates that doesn't belong there. Templates also restrict what can be put in a template. Smarty's simple are simpler, more intuitive, and less fragile than PHP statements. PHP syntax works well for application code, but quickly degenerates when mixed with HTML.
PHP works well for programming, but not so well for templating. Although this approach is fast from a pure script-execution point-of-view, many would argue that the PHP syntax is messy and difficult to maintain when mixed with presentation. This approach simply mixes PHP code with HTML. The first camp exclaims that "PHP is a template engine". When it comes to templating in PHP, there are basically two camps of thought. This implies that PHP code is application logic, and is separated from the presentation. Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.