PHAML

From Wikipedia, the free encyclopedia

pHAML
Developed by David Moring
Latest release 0.9 (preview release) / August 4, 2007
OS Cross-platform
Genre Template Engine
License MIT License
Website i.cloudi.us

pHAML (php XHTML Abstraction Markup Language) is a PHP-centric variant of Haml. Haml is a markup language that is used to cleanly and simply describe the XHTML of any web document without the use of traditional inline coding.

pHAML adds additional PHP capabilities to Haml, beyond those provided by phpHaml, including template inclusion, variable inclusion, debugging capabilities that have proven valuable and time savings in development. pHAML is live software in production in several sites.

Contents

[edit] pHAML and Haml Similarities

There is no greater fan of the principles behind HAML than pHAML, markup should be beautiful, DRY (don't repeat yourself), well-indented, and the XHTML structure should be clear.

  • The tag creating syntax was kept the same.
  • Spaces are VERY important—tabs and spaces are not equal and may produce “interesting” results (hence the addition of the debugging capability).

[edit] pHAML and Haml Differences

This solution was created to enhance Smarty, and also can be integrated into the Zend Framework. There have been other tweaks to assist in the creation of code. Also, PHP and Ruby share a bit, but are a bit different as well.

  • Attributes are literal: there is no Ruby array notation for attribute arrays.
  • Spaces are not tied to a multiple of two (fight the man!!), but you should make your code spacing consistent in practice.
  • There are comments (not just the HTML kind).
  • There is no Ruby code integration.
  • There is PHP integration.
  • There are debugging commands, a simple template system, heredoc syntax, html character output, and html4 doctype tags.
  • Smarty integration.
  • Zend Framework integration.
  • All in a compact single PHP class.

[edit] Examples

[edit] Example of Code

[edit] The pHAML Code

!!!
%html
  %head
    %title Hello World
  %body
    %b Hello World
Generated Template:
    1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2   <html>
    3     <head>
    4       <title>
    5       Hello World
    6       </title>
    7     </head>
    8     <body>
    9       <b>
   10       Hello World
   11       </b>
   12     </body>
   13   </html>
   14   

The HTML output listing with line numbers is a function in the Zend Framework View that is under testing and will be release with the 1.0 version.

[edit] Example with Embedded Debugger On

By simply starting a line with a '?', the class will produce HTML comments that are useful in debugging.

?
!!!
%html
  %head
    %title Hello World
  %body
    %b Hello World
Generated Template:
    1       <!-- Debug on -->
    2       <!-- 3:4{!!!}: !!! -->
    3       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4       <!-- 4:4: %html -->
    5       <html>
    6         <!-- 5:6: %head -->
    7         <head>
    8           <!-- 6:8: %title Hello World -->
    9           <title>
   10           Hello World
   11         <!-- 7:6: %body -->
   12           </title>
   13         </head>
   14         <body>
   15           <!-- 8:8: %b Hello World -->
   16           <b>
   17           Hello World
   18           </b>
   19         </body>
   20       </html>
   21   

[edit] Current Status

Technical preview is available at Source Forge, Source Forge Site.

[edit] External links