Yet another Haml to HTML converter written in PHP.
PHP JavaScript CSS Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src/HamlPHP
test Adds :markdown and :markdownextra filters Jul 10, 2012
.gitignore
.gitmodules
MIT-LICENSE First commit Nov 18, 2010
README.mkd
composer.json

README.mkd

HamlPHP

Yet another Haml to HTML converter written in PHP.

Check the Wiki we've been adding some docs.

Requirements

PHP 5.2 or newer.

Usage

The simplest way to use HamlPHP is to manually. You can use mod_rewrite to redirect all your requests to index.php and render the .haml files from there. We'll add this example later. HamlPHP will cache compilation results, so the .haml file is only compiled to php once.

index.haml

!!! 5
%html
    %body
        #container
            %ul.navigation
                %li Etusivu
                %li Tuotteet

            %h2 Tuotteet
            %ul.products
                - for ($i = 0; $i < 10; $i++)
                    %li= $i * 7

In your index.php

<?php
require_once 'src/HamlPHP/HamlPHP.php';
require_once 'src/HamlPHP/Storage/FileStorage.php';

// Make sure that a directory _tmp_ exists in your application and it is writable.
$parser = new HamlPHP(new FileStorage(dirname(__FILE__) . '/tmp/'));

$content = $parser->parseFile('index.haml');

echo $parser->evaluate($content);

The compilation result will look like this:

<!DOCTYPE html>
<html>
  <body>
    <div id="container">
      <ul class="navigation">
        <li>Etusivu</li>
        <li>Tuotteet</li>
      </ul>
      <h2>Tuotteet</h2>
      <ul class="products">
        <li>0</li>
        <li>7</li>
        <li>14</li>
        <li>21</li>
        <li>28</li>
        <li>35</li>
        <li>42</li>
        <li>49</li>
        <li>56</li>
        <li>63</li>
      </ul>
    </div>
  </body>
</html>