如何在 fuelPHP 中使用 haml 视图?

How to use haml views with fuelPHP?

我正在尝试使用 HAML with fuelPHP 1.8

第一

我按照 https://github.com/fuel/parser 的建议更新了 composer.json

require 部分
"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": "*"
},

然后

我用非常简单的 HAML 编写了 my-view.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

然后在控制器中我用

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

但是

我收到以下错误:

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

那么

investigations I replaced my-view.haml by this twig版本之后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

当我指向 my-view.haml.twig

Twig 似乎根本不知道 HAML

Twig_Error_Syntax [ Error ]:
Unknown "haml" tag.

我迷路的地方

将 HAML 与 fuelPHP 一起使用的正确方法是什么?

讨论后 fuelPHP forum an issue 已打开。

这是 haml 解析器 造成的错误。它与 twig 2.

不兼容

我通过删除无用的解析器并将 twig 移动到版本 1.31.0 暂时解决了我的问题,如下所示:

"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": "*"
},