【发布时间】:2014-02-04 10:33:27
【问题描述】:
我已经在 CakePHP 应用程序中安装了 TwigView,我正在尝试在名为 default.twig.tpl 的默认模板中加载元素 header.twig.tpl 和 footer.twig.tpl。
这个很好用:
<!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>
当我尝试使用CakePHP 默认Helpers 时,问题就开始了,它们被简单地忽略了。
我不知道为什么,如果我尝试:
<!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>
忽略该方法而不会抛出错误,并且页面仍然像从未调用过一样工作。
我已经关注了所有 TwigView explanation,但它仍然无法正常工作,我错过了什么?
我也在尝试使用 Twig 函数,但由于某种原因它们似乎没有加载:
{{ 'FOO'|low }}
抛出错误:
Fatal error: Call to undefined function low() in .../app/Plugin/TwigView/tmp/views/2d/4b/65accc...92.php on line 45
【问题讨论】:
-
正如我所说我没有得到错误,它们被忽略了。
-
我还发现twig找不到
dump方法{{ dump(some_var) }},并抛出错误:The function "dump" does not exist in "Layouts/default.twig.tpl" at line 22 -
我也有加载树枝到 cakephp 的问题,你能告诉我如何加载插件吗?
标签: twig helper template-engine cakephp-2.4