Search code examples
twighelpertemplate-enginecakephp-2.4

Using CakePHP helpers with TwigView plug-in not working


I've installed TwigView inside my CakePHP application and I'm trying loading the elements header.twig.tpl and footer.twig.tpl inside the default template called default.twig.tpl.

It works fine with this:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Hello world!</title>

</head>
<body>
{% element 'header.twig' %}

    {{ test_var_from_controller }} <!-- this works and echoes "Hello world!" as expected -->

{% element 'footer.twig' %}
</body>
</html>

The problem starts when I try to use CakePHP default Helpers, they are simply ignored.

I'm not sure why, if I try:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Hello world!</title>
    {{ html.css('styes.min') }}
</head>

The method is ignored without throw errors and the page still working like it was never called.

I've followed all the TwigView explanation but it still not working, what I'm missing?

I'm also trying using Twig functions and they seems to be not loaded for some reason:

{{ 'FOO'|low }}

Throws the error:

Fatal error: Call to undefined function low() in .../app/Plugin/TwigView/tmp/views/2d/4b/65accc...92.php on line 45

Solution

  • I've found the problem, i needed to load the Helpers inside AppController first

    class AppController extends Controller {
        public $viewClass = 'TwigView.Twig';
        public $ext = '.twig.tpl';
        public $helpers = array('Html', 'Form');
    }