ghassen lassoued
ghassen lassoued

Reputation: 59

How to pass JavaScript variable to Symfony route using Twig path function

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

photo

Upvotes: 2

Views: 2233

Answers (1)

Le Menach Florian
Le Menach Florian

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

Related Questions