如何从控制器到布局打印变量?

时间:2018-08-21 12:36:58

标签: twig drupal-8

控制器:

public function content() {    
      return array(
        '#theme' => 'test',
        '#varTest' => 'toto'
      );
  }

模块主题挂钩:

function test_theme($existing, $type, $theme, $path) {
  return [
    'test' => [
      'variables' => ['varTest' => 'defaultVal']
    ]
  ];
}

布局html.html.twig:

  <html>
      <head>
        {{ varTest }}

如果我在布局中打印变量varTest为null。如果我在模板“ test”中打印变量,则varTest ='toto'

为什么布局不打印“ toto”或“ defaultVal”?

0 个答案:

没有答案
相关问题