hamlphp/hamlphp

There is no license information available for the latest version (dev-master) of this package.

Yet another Haml to HTML converter written in PHP.

dev-master 2015-01-19 14:51 UTC

This package is not auto-updated.

Last update: 2024-05-03 16:01:36 UTC


README

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>