twighamlfuelphp

How to use haml views with fuelPHP?


I'm trying using HAML with fuelPHP 1.8

First

I followed piece of advices from https://github.com/fuel/parser 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": "*"
},

Then

I wrote my-view.haml in very simple HAML

!!!
%html
  %head
    %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"}/
  %body
    %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);
}

But

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

So

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

{% haml %}
!!!
%html
  %head
    %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"}/
  %body
    %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 ?


Solution

  • After discussion on fuelPHP forum an issue as been opened.

    This is a bug due to haml parser. It is not compatible with twig 2.

    I temporary solved my case by removing useless parsers and moving twig to version 1.31.0 as following:

    "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",
        "twig/twig" : "1.31.0",
        "mthaml/mthaml": "*"
    },