I tried to render a controller inside twig. I follow the documentation "Embedding other Controllers".
I constantly get an exeption with the method render(controller()): An exception has been thrown during the rendering of a template ("")
In my template.html.twig
{{ render(controller('MyBundle:User:logo')) }}
In my controller
class UserController extends Controller {
public function logoAction()
{
return $this->render('MyBundle:User:logo.html.twig', []);
}
}
It work well if I use in my template
{% render url('logo') %}
With the route
logo:
pattern: /logo
defaults: { _controller: MyBundle:User:logo }
But I want to use render(controller())
What do I do wrong?
Edit, add more info about exception:
An exception has been thrown during the rendering of a template ("") in MyBundle:My/Dashboard:dashboard.html.twig at line 51.
500 Internal Server Error - Twig_Error_Runtime 1 linked Exception: ResourceNotFoundException ยป
[2/2] Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("") in MyBundle:My/Dashboard:dashboard.html.twig at line 51. -
in app/cache/dev/classes.php at line 7378 - } catch (Twig_Error $e) { throw $e; } catch (Exception $e) { throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getTemplateName(), $e); } } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); at Twig_Template
->displayBlock ('body', array('preset' => array('date' => '2015-03-31'),... 1/2] ResourceNotFoundException: -
in app/cache/dev/appDevUrlMatcher.php at line 632 -
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
} } at appDevUrlMatcher ->match ('/_fragment') in app/cache/dev/classes.php at line 3278 + at Router ->match ('/_fragment')
Edit2 dashboard.html.twig
{% block body %}
<div class="panel panel-default">
<div class="panel-heading">
<span class="glyphicon glyphicon-random" aria-hidden="true"></span>
<b>{{ "Request"|trans }}</b>
</div>
<div class="panel-body">
<form role="form" action="{{ path('dashboard', {'idDbd': idDbd}) }}">
<div class="form-inline">
{{ render(controller('MyBundle:User:logo')) }}
</div>
{% include 'MyBundle:My/Request:request_edit.html.twig' %}
</form>
</div>
</div>
(...)
/src/MyBundle/Resources/views/User/logo.html.twig
- HeahDashboard:dashboard.html.twig
files indicating the line 51? - Matteo