HAH - Hah Ain't HAML

Welcome to the home of HAH

HAH Ain't Haml (but it's close) is a PHP parser and renderer for a template / domain specific language similar to HAML. It was heavily inspired by HAML. I liked the general concept but wanted to take it a little further by minimizing the number of language constructs you needed to know as well as make it easier to use in a PHP environment.

Here's a small example of a HAH document

    title My example page

         !banner.png( border="0" alt="My example Page" )
         !topmenu.hah( color="#fff" )
           @pagetype= $pagetype

         #message=? $special_message

         h1= $welcome_message
         p Here's a list pages on the site
           - foreach ( $pages as $page )
             li= $page

            This is the <em>footer</em> for my example page.

    ? ( $loggedin )
      span= "You are logged in as " . $username
      a( href="login" ) Login Here

This HAH document will produce the following code.

    <title>My example page</title>
    <link href="styles.css" type="text/css" rel="stylesheet" />
    <script src="functions.js" type="text/javascript"></script>
    <div id="page">
      <div id="header">
        <img src="banner.png" border="0" alt="My example Page" />
          $__subhahdoc = new HahDocument('.topmenu.hah'); 
          echo $__subhahdoc; unset($__subhahdoc);  
        <?php if (HahNode::pick($special_message) != '') { ?>
          <div id="message">
            <?php echo HahNode::pick($special_message); ?>
        <?php } ?>
      <div id="main" class="left">
        <h1><?php echo $welcome_message; ?></h1>
        <p>Here's a list pages on the site</p>
          <?php foreach ( $pages as $page ) { ?>
            <li><?php echo $page; ?></li>
          <?php } ?>
      <div id="footer">         
        <p>This is the <em>footer</em> for my example page.</p>
    <?php if (( $loggedin )) { ?>
      <span><?php echo "You are logged in as " . $username; ?></span>
    <?php } else { ?>
      <a href="login">Login Here</a>
    <?php } ?>

This example shows a byte reduction from 1,337 to 627. Of course size is not the problem HAH is trying to address. HAH is concerned with readability and reducing the amount of time and energy required to produce PHP templates.