Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PHP Templating Systems


Published on

Published in: Technology
  • Be the first to comment

PHP Templating Systems

  1. 1. PHP Templating Systems<br />April 26, 2011<br />NWO-PUG <br />1<br />E-mail:<br />Twitter: @dragonmantank<br /> dragonmantank<br />
  2. 2. Who Are You and Why Are You In My House?<br />Chris Tankersley<br />Doing PHP for 8 Years<br />Lots of projects no one uses, and a few that some do<br />TL;DR<br />April 26, 2011<br />NWO-PUG <br />2<br />
  3. 3. What?<br />Templating Systems allow easy replacement of variable text, or to re-use text in multiple places<br />April 26, 2011<br />NWO-PUG <br />3<br />PHP itself is actually a template system<br />
  4. 4. Think about it<br />April 26, 2011<br />NWO-PUG <br />4<br />
  5. 5. Why not just use PHP?<br />Not everyone wants to learn PHP<br />Separation of Presentation and Logic<br />You can still use PHP, like we’ll see in a bit<br />April 26, 2011<br />NWO-PUG <br />5<br />
  6. 6. Rolling Your Own<br />Because re-inventing the bicycle is awesome<br />April 26, 2011<br />NWO-PUG <br />6<br />
  7. 7. Search and Replace<br />Not as easy as it sounds<br />Have to select a syntax<br />How do you handle files?<br />How does logic work?<br />April 26, 2011<br />NWO-PUG <br />7<br />
  8. 8. Manipulate Those Strings <br />Template File – template.phtml<br />Get The File Contents<br />April 26, 2011<br />NWO-PUG <br />8<br />
  9. 9. Manipulate Those Strings<br />Register some variables<br />Replace!<br />April 26, 2011<br />NWO-PUG <br />9<br />
  10. 10. Congrats! <br />This is a template system<br />It is just not a good template system<br />Inefficient<br />Memory hog<br />Doesn’t handle logic structures<br />April 26, 2011<br />NWO-PUG <br />10<br />
  11. 11. Buying a Bicycle<br />Because building one from scratch won’t be as good<br />April 26, 2011<br />NWO-PUG <br />11<br />
  12. 12. What Do We Look For?<br />Easy syntax<br />Logic Control<br />Layered Templating<br />Easy Integration<br />Compilation<br />Caching<br />April 26, 2011<br />NWO-PUG <br />12<br />
  13. 13. Shoulders of Giants<br />Smarty<br />One of the oldest templating systems<br />Twig<br />Part of the symfony framework, but standalone<br />mustache.php<br />Great if you’re also doing JS templating<br />Built-in systems in other frameworks<br />Not as portable most of the time<br />April 26, 2011<br />NWO-PUG <br />13<br />
  14. 14. Smarty<br />April 26, 2011<br />NWO-PUG <br />14<br />
  15. 15. Smarty Template<br />April 26, 2011<br />NWO-PUG <br />15<br />
  16. 16. In PHP<br />April 26, 2011<br />NWO-PUG <br />16<br />
  17. 17. Why Use Smarty?<br />Lots of people know it<br />Supports Caching of templates<br />Variable creation in the template<br />PHP has no idea what {$counter} is<br />Markup is simple enough for designers<br />April 26, 2011<br />NWO-PUG <br />17<br />
  18. 18. Twig<br />April 26, 2011<br />NWO-PUG <br />18<br />
  19. 19. Twig Template<br />April 26, 2011<br />NWO-PUG <br />19<br />
  20. 20. In PHP<br />April 26, 2011<br />NWO-PUG <br />20<br />
  21. 21. Why Use Twig?<br />More modern than Smarty<br />Gateway drug into symfony development<br />April 26, 2011<br />NWO-PUG <br />21<br />
  22. 22. {{ mustache.php }}<br />April 26, 2011<br />NWO-PUG <br />22<br />
  23. 23. Template File<br />April 26, 2011<br />NWO-PUG <br />23<br />
  24. 24. In PHP<br />April 26, 2011<br />NWO-PUG <br />24<br />
  25. 25. Why use mustache?<br />Cross-language<br />Supports JS, PHP, Ruby, Python<br />Syntax is easy<br />IDE Integration<br />April 26, 2011<br />NWO-PUG <br />25<br />
  26. 26. Frameworks<br />April 26, 2011<br />NWO-PUG <br />26<br />
  27. 27. Have to Output HTML Somehow<br />Zend Framework has Zend_View<br />Symfony has Twig<br />Lithium, CakePHP, Fuel all have one<br />Most of the time these work great<br />April 26, 2011<br />NWO-PUG <br />27<br />
  28. 28. Be Careful<br />Most of the framework templating systems are not portable (except Twig)<br />Most of the time hard to swap them out for something else<br />April 26, 2011<br />NWO-PUG <br />28<br />
  29. 29. So what do we gain?<br />Other than more hard drive space used<br />April 26, 2011<br />NWO-PUG <br />29<br />
  30. 30. A few things…<br />Presentation and Business Logic are separated<br />Only logic in the template is for output<br />We gained output caching<br />We gained the ability to have non-programmers work on our designs<br />In the case of Twig/Smarty, there is now a portable output renderer<br />April 26, 2011<br />NWO-PUG <br />30<br />
  31. 31. Questions?<br />April 26, 2011<br />NWO-PUG <br />31<br />
  32. 32. Links<br />Where to Find Stuff I Talked About<br />April 26, 2011<br />NWO-PUG <br />32<br />
  33. 33. Links<br />Smarty<br /><br />Twig<br /><br />mustache.php<br /><br />April 26, 2011<br />NWO-PUG <br />33<br />