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?
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)
You can inject templating
service to render twig template and store it in a variable.