(CakePHP 2.x) $this->assign() with twig
(CakePHP 2.x) $this->assign() with twig
你好如何将这部分代码与 twig 一起使用,
$this->assign('title', 'Home');
没有
echo $this->assign('title', 'Home');
我试过了,
{% set assign = ('title', 'Home') %}
{% set this.assign = ('title', 'Home') %}
{% set assign = {'title', 'Home'} %}
{{ assign('title', 'Home') }}
但是还是不行
谢谢你
我不知道如何在模板上下文中使用 $this
(它会引用一些生成的 class 实例),但是您可以使用 do
statement.
The do tag works exactly like the regular variable expression ({{ ... }}) just that it doesn't print anything:
{% do 1 + 2 %}
要在使用 TwigView 时访问视图本身,请使用 _view
变量:
{% do _view.assign('title', 'Home') %}
你好如何将这部分代码与 twig 一起使用,
$this->assign('title', 'Home');
没有
echo $this->assign('title', 'Home');
我试过了,
{% set assign = ('title', 'Home') %}
{% set this.assign = ('title', 'Home') %}
{% set assign = {'title', 'Home'} %}
{{ assign('title', 'Home') }}
但是还是不行
谢谢你
我不知道如何在模板上下文中使用 $this
(它会引用一些生成的 class 实例),但是您可以使用 do
statement.
The do tag works exactly like the regular variable expression ({{ ... }}) just that it doesn't print anything:
{% do 1 + 2 %}
要在使用 TwigView 时访问视图本身,请使用 _view
变量:
{% do _view.assign('title', 'Home') %}