Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to use haml views with fuelPHP?

  • I'm trying using HAML with fuelPHP 1.8


    I followed piece of advices from by updating require part of composer.json

    "require": {
    "php": ">=5.3.3",
    "composer/installers": "~1.0",
    "fuel/core": "1.8.*",
    "fuel/auth": "1.8.*",
    "fuel/email": "1.8.*",
    "fuel/oil": "1.8.*",
    "fuel/orm": "1.8.*",
    "fuel/parser": "1.8.*",
    "fuelphp/upload": "2.0.6",
    "monolog/monolog": "1.18.*",
    "phpseclib/phpseclib": "2.0.0",
    "michelf/php-markdown": "1.4.0",
    "dwoo/dwoo" : "*",
    "mustache/mustache" : "*",
    "smarty/smarty" : "*",
    "twig/twig" : "*",
    "mthaml/mthaml": "*",
    "pyrocms/lex": "*"


    I wrote my-view.haml in very simple HAML

    %meta{:charset => "utf-8"}/
    %title My View
    %meta{:content => "width=device-width, user-scalable=no, initial-scale=1.0", :name => "viewport"}/
    %link{:href => "assets/style.min.css", :rel => "stylesheet"}/
    %h1 this is my view

    Then in a controller I pointed to my-view.haml with

    public function action_view()
    $view = View::forge('welcome/my-view.haml');
    return Response::forge($view, 200);


    I obtain following error:

    ErrorException [ Fatal Error ]:
    Method Parser\View_HamlTwig::__toString() must not throw an exception,
    caught TypeError: Argument 1 passed to Twig_Environment::__construct()
    must be an instance of Twig_LoaderInterface,
    null given, called in /home/mickro/devel/my-prj/fuel/packages/parser/classes/view/twig.php on line 104


    After investigations I replaced my-view.haml by this twig version my-view.haml.twig

    {% haml %}
    %meta{:charset => "utf-8"}/
    %title My View
    %meta{:content => "width=device-width, user-scalable=no, initial-scale=1.0", :name => "viewport"}/
    %link{:href => "assets/style.min.css", :rel => "stylesheet"}/
    %h1 this is my view

    when I point to my-view.haml.twig

    Twig seems not to know HAML at all

    Twig_Error_Syntax [ Error ]:
    Unknown "haml" tag.

    Where I'm lost

    What is the right way to use HAML with fuelPHP ?

  • HarroHarro
    Accepted Answer
    There was no need to add all suggestions to your composer.json, all you need is "mthaml" if you want to use HAML on itself, and "twig" if you want to use HAML in combination with Twig.

    The default configuration is to use it with Twig, see the parser config file: (and uses the '.haml' extension for views).

    The problem is that de parser package module for HAML is written for Twig v1.x, while your composer.json configuration loads the latest version, which is a 2.x. The twig module itself has been adapted recently, but this one seems to have been forgotten.

    I'll put it on the todo list. (
  • Thanks for explanations.

    I removed unnecessary packages. And moved twig to version 1.31.0

    My haml views work fine this way.

    Looking forward for your fix to make haml parser compatible with twig 2.
  • Will try to move it up the list, and report back here when done.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion