Get Smart Use Smarty


Published on

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. I stress the word Framework because 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.

Join BostonPHP and Michael Bourque as he takes you through the Smarty Framework. This will be an interactive session where Michael will write code and demonstrate throughout the session. You will leave with the tools and information to apply Smarty to your next project:

What is Smarty? Learn why it is good to separate the presentation code from the business logic of your application

* Smarty syntax and functions
* Best practices and demos
* How to use a terminology property file to make it easier to control application terminology and software strings outside of your code.
* Learn how to offer multiple language support and switching in your application
* Plenty of time for your questions and answers

See why so many others love using Smarty in their projects. You will too and I will show you how. Invite your PHP friends, your CSS/Design team - you don't want to miss this one.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Get Smart Use Smarty

  1. 1. Get Smart Use Smarty Michael Bourque Boston PHP May 6, 2009
  2. 2. What I hope to cover <ul><li>Why Smarty? </li></ul><ul><li>Installation </li></ul><ul><li>Smarty syntax overview </li></ul><ul><li>Some examples and demos </li></ul><ul><li>L10n & I18n (AKA Localization) </li></ul><ul><li>Cool effects to add to your web app </li></ul><ul><li>Q & A </li></ul>
  3. 3. What’s so smart about smarty? <ul><li>Separate view from business logic </li></ul><ul><ul><li>If your not already using an MVC framework </li></ul></ul><ul><li>Designers cant break the business code </li></ul><ul><li>Easy to read / Easy to use </li></ul><ul><li>Useful built in functions and modifiers </li></ul><ul><li>Optional content caching </li></ul><ul><li>Configuration files </li></ul>
  4. 4. What’s not smart about smarty? <ul><li>What critics say… </li></ul><ul><li>Performance </li></ul><ul><ul><li>Nothing is faster than PHP </li></ul></ul><ul><li>Security Claim </li></ul><ul><ul><li>No extra security </li></ul></ul><ul><li>Better templating solutions </li></ul><ul><li>Debugging is better with Firebug / FirePHP </li></ul><ul><li>etc… </li></ul>
  5. 5. Have you ever done this?
  6. 6. Have you ever had to work on this?
  7. 7. MVC <ul><li>Model </li></ul><ul><li>View </li></ul><ul><li>Controller </li></ul>
  8. 9. Controller Controller View View Model
  9. 10. Easier to maintain this!
  10. 11. Controller View Model Business Logic Data layer Flow control Presentation
  11. 12. Get Smart : Installation <ul><li>Download it from, Subversion, or Pear: </li></ul><ul><ul><li>pear channel-discover </li></ul></ul><ul><ul><li>pear install smarty/smarty </li></ul></ul><ul><li>Create cache and template folders </li></ul><ul><ul><li>cache </li></ul></ul><ul><ul><li>templates_c </li></ul></ul><ul><li>Include it </li></ul><ul><ul><li>include('Smarty.class.php'); </li></ul></ul><ul><ul><li>$smarty = new Smarty; </li></ul></ul>
  12. 13. Get Smart : Usage <ul><li>Basic syntax </li></ul>
  13. 14. Get Smart : Examples <ul><li>Comments </li></ul><ul><ul><li>{* this is a comment *} </li></ul></ul><ul><li>Variables </li></ul><ul><ul><li>{$variable}, {$array[4]}, {$array.key.key}, $object->property} </li></ul></ul><ul><li>Functions </li></ul><ul><ul><li>{config_load file=}, {include file=}, {if}{else}{/if}, {foreach} </li></ul></ul><ul><li>Modifiers </li></ul><ul><ul><li>{$date|date_format}, {$title|truncate:40:'...'} </li></ul></ul><ul><li>$smarty </li></ul><ul><ul><li>{$}, {$smarty.cookies.username}, {$smarty.request.username} </li></ul></ul>
  14. 15. Get Smart : Tips <ul><li>Loops </li></ul><ul><li>Config Files </li></ul><ul><li>Sending emails </li></ul><ul><li>Escaping </li></ul><ul><li>Caching </li></ul><ul><li>Debugging </li></ul>
  15. 16. Get Smart : Demo <ul><li>Get Smarty Demo </li></ul><ul><li>Language files </li></ul><ul><li>Sending emails </li></ul><ul><li>Progressive Enhancement </li></ul><ul><li>jQuery </li></ul>
  16. 17. Q/A
  17. 18. Thank you… <ul><li>Contact me </li></ul><ul><li>[email_address] </li></ul>