0

Let's say i have my own class

  <?php
  class myClass {
    public function myFunction(){
    $template = $this->render('sometwigfile');
    }
  }

What should i do if I want to load twig file to variable NOT IN CONTROLLER?

mcz
  • 1
  • 1

2 Answers2

0

Simply use :

$template = $this->renderView('whatever.html.twig')

render() renders the full HTTP response including the headers, and returns a Response object, while renderView() just gives you the rendered view (i.e. some HTML, in your case)

tchap
  • 3,412
  • 3
  • 29
  • 46
0

You can inject templating service to render twig template and store it in a variable.

Mateusz Sip
  • 1,280
  • 1
  • 11
  • 11