php templating systems

Download PHP Templating Systems

Post on 18-Nov-2014

4.575 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

 

TRANSCRIPT

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