PHPackages                             kriss0r/php-haml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. kriss0r/php-haml

ActiveLibrary[Templating &amp; Views](/categories/templating)

kriss0r/php-haml
================

Fork of PHPHaml to integrate bug fixes

0121PHP

Since Aug 22Pushed 4y agoCompare

[ Source](https://github.com/kriss0r/phphaml)[ Packagist](https://packagist.org/packages/kriss0r/php-haml)[ RSS](/packages/kriss0r-php-haml/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (1)

This is a fork of the [PHPHaml project](http://phphaml.sourceforge.net/). I thought it would be more effective to track patches using github rather than just emailing them to upstream.

So far the patches included here are:

- "magic else" -- PHPHaml allows templates like the following:

    ```
    - if(false)
      Hi
    - else
      Bye
    ```

    However, upstream breaks on this "else" because the regex being used to look for this case doesn't match the code that generates it.
- switch support:

    ```
    - switch($error)
      - case 'captcha'
        invalid captcha code
      - case 'empty_name'
        Please enter your name
      - case 'empty_comment'
        Please enter your message
      - default
        unrecognisable error
    ```

    However, multiple case statemetns still unsupported:

    ```
    - case 0
    - case 1
    ```
- dashes in id names: fix a bug where ids like `#abc-def` weren't recognized as XHTML ids.
- arrays as hashes: allow passing hashes to the element attribute tag, like this:

    ```
    - $ary = array('name' => 'myname', 'href' => "#myname")
    %a{ $ary, :rel => 'link' }
    ```

    The behavior is not exactly like Ruby HAML, because the attributes specified in the element itself will all come at the end, but it's a start.
- pipe handling: Ruby HAML treats this as a special case:

    ```
    Some text
    |
    More text
    ```

    If a pipe is the first character on a line, not counting indentation, it does not count as a line break. Since HTML designers tend to use the pipe character as a separator, it's important to get this case right.
- commas: Ruby HAML doesn't do much processing on attribute elements, which allows you to do things like this:

    ```
    %a{ :href=>"a,b,c", :target => "_blank" }
    ```

    PHPHaml has to do some processing here to transform `:href` into `"href"` and put everything into an `array()`. To do this, it splits on commas, which is obviously problematic if one of your values has a comma in it.

    The patch to fix this relies on the similarity between attribute-hash syntax in HAML and an argument array, and simply runs a regex to map :symbol to "symbol". Then we don't have to split on commas in order to split up arguments -- the PHP parser will do it for us.

    This might give you pause, because of the "arrays as hashes of attributes" feature above. But this works, due to a PHP oddity -- arrays can have both numeric and non-numeric keys, and the syntax expressly allows you to mix them, as follows:

    ```
    $a = array('foo' => 'bar', 'baz');
    ```

    ($a\['foo'\] is 'bar', and $a\[0\] is 'baz'.) Using this behavior, we can still rely on array literal syntax:

    ```
    %a{ :href=>$key, $arguments }
    ```

    becomes:

    ```
    >
    ```

    And the writeAttributes method is smart enough to recognize that $value has an integer key, so render it recursively.
- reentrancy: previously PHPHaml had a giant static $aVariables array, which was modified by calling assign() on *any* HamlParser object. This sucks if you have multiple HamlParsers, want to render HAML recursively, etc. Turning that into an object-local variable was pretty trivial. Additionally, we found it convenient to pass a $context array to render(), which is used in addition to $this-&gt;aVariables, to populate the scope of the HAML code.
- class design: PHPHaml upstream has all HAML processing logic in one huge HamlParser class. It turns out you can decompose this at least a little bit into a HamlLine class, which corresponds roughly to a node in a parse tree, with one line of HAML to compile and some number of children, and a HamlParser that subclasses HamlLine and adds some whole-file code. This is a little easier to work with.
- whitespace eaters. HAML defines two element modifiers that eat whitespace: %foo&gt; and %foo&lt;. PHPHaml upstream supports neither; we only support the outside-the-element eater (%foo&gt;).
- html-style attributes:

    ```
    %input( type="text" onclick="this.value = 'cliked'; this.attributes.disabled = 'disabled';" value='Click me' )
    ```
- Silent haml comments -#

    ```
    -# I am comment
      And i am
    ```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/fafb923e05a0e4cdd0cd6a6093f3452ce75aab95949121e7ab180686343dce14?d=identicon)[kriss0r](/maintainers/kriss0r)

---

Top Contributors

[![glasserc](https://avatars.githubusercontent.com/u/17006?v=4)](https://github.com/glasserc "glasserc (32 commits)")[![alozytskyy](https://avatars.githubusercontent.com/u/42665348?v=4)](https://github.com/alozytskyy "alozytskyy (23 commits)")[![everzet](https://avatars.githubusercontent.com/u/30813?v=4)](https://github.com/everzet "everzet (4 commits)")[![kriss0r](https://avatars.githubusercontent.com/u/476914?v=4)](https://github.com/kriss0r "kriss0r (4 commits)")[![derDoc](https://avatars.githubusercontent.com/u/882759?v=4)](https://github.com/derDoc "derDoc (1 commits)")[![tyaga](https://avatars.githubusercontent.com/u/27217?v=4)](https://github.com/tyaga "tyaga (1 commits)")

### Embed Badge

![Health badge](/badges/kriss0r-php-haml/health.svg)

```
[![Health](https://phpackages.com/badges/kriss0r-php-haml/health.svg)](https://phpackages.com/packages/kriss0r-php-haml)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
