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



    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 ?


  • 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: https://github.com/fuel/parser/blob/1.8/master/config/parser.php#L32 (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. (https://github.com/fuel/parser/issues/93)
  • 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