Generating routes in javascript with Twig and Symfony2

I know it’s an old question, but just in case you don’t want to install a bundle like FOSJsRoutingBundle, here’s a little hack: var url=”{{ path(“yourroute”, {“region_id’: ‘region_id’}) }}’; url = url.replace(“region_id”, this.value); ‘region_id’ is just used as a placeholder, then you replace it in JS with your actual variable this.value