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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)