How to define global variable for Twig

后端 未结 3 690
死守一世寂寞
死守一世寂寞 2020-12-16 01:33

I\'m using a file serving as a form layout to overwrite certain elements (form_start, form_row, etc.). I register it like:

twig:
    - Acme         


        
3条回答
  •  感动是毒
    2020-12-16 02:28

    You can use addGlobal() method.

    For example in BaseController I use:

    $this->get('twig')->addGlobal('is_test', $isTest);
    

    so in your case you should probably do:

    $this->get('twig')->addGlobal('var', $var);
    

提交回复
热议问题