Reputation: 59
I have a small problem with a Javascript variable in a Twig template, what I want is to pass a variable as a parameter (in a url) to a function. All I have found on StackOverflow is how to pass a string 'blablabla' to the URL like:
url/{param}, {'param' : 'blablabla'}
but I want something like :
$var =...;
url/{param}, {'param': $var}
this photo should make it clear to you , thanks for reading
Upvotes: 2
Views: 2233
Reputation: 462
I advise you to use the FOS JsRouting bundle. It is totally suited to what you want to do.
Here is the official documentation : https://symfony.com/doc/current/bundles/FOSJsRoutingBundle/usage.html
Example in Twig :
Routing.generate('your_route_with_params', { param: varJavascript });
Enjoy
Upvotes: 2