0

I'm rendering data from a CMS via Twigcode to a Controller and the Controller renders a twig template. I'd like to have the current route. I already tried to use:

// Controller
$request = $this->container->get('request');
$routeName = $request->get('_route');

// or Twigtemplate
{{ app.request.attributes.get('_route') }}

But the result is "_internal". How can I solve that problem?

J. Steen
  • 15,470
  • 15
  • 56
  • 63
raphidue
  • 141
  • 1
  • 1
  • 7

1 Answers1

0

You forgot the call to the Twig path function in your Twig template!

{{ path(app.request.attributes.get('_route')) }}

instead of

{{ app.request.attributes.get('_route') }}

Hope it helps!

Michaël Perrin
  • 5,903
  • 5
  • 40
  • 65
  • im getting an Exception: An exception has been thrown during the rendering of a template ("The "_internal" route has some missing mandatory parameters ("controller", "path", "_format").") – raphidue Jan 07 '13 at 11:12
  • See this comment: http://stackoverflow.com/questions/7096546/how-to-get-current-route-in-symfony-2#comment14132455_7777229 . I guess your template is rendered in the standalone mode. – Michaël Perrin Jan 07 '13 at 11:21
  • sorry im not using the standalone mode :( – raphidue Jan 07 '13 at 11:36
  • Do you use this method in the main template or is an included templae? In that case, do you use {% render(...) %} or {% include(...) %}? – Michaël Perrin Jan 07 '13 at 11:39
  • I use that statement in the main twig template the template is call by the symfony render statement in a COntroller – raphidue Jan 07 '13 at 11:51
  • Hum, I don't have a clue now... Which version of Symfony do you use? If you can give some code extracts of your controller, that might help. – Michaël Perrin Jan 07 '13 at 13:07