How to Generate Routing URLs in JavaScript ========================================== If you're in a Twig template, you can use the same ``path`` function to set JavaScript variables. The ``escape`` function helps escape any non-JavaScript-safe values: .. configuration-block:: .. code-block:: html+twig .. code-block:: html+php But if you *actually* need to generate routes in pure JavaScript, consider using the `FOSJsRoutingBundle`_. It makes the following possible: .. code-block:: javascript var url = Routing.generate('blog_show', { 'slug': 'my-blog-post' }); .. _`FOSJsRoutingBundle`: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle